Htaccess rewrite rules cause an error when submitting a form

I am working with my htaccess file to configure the layout of URLs on my site.

The problem at the moment is that I can no longer submit any forms.

I have two files that will definitely contain the same code (copy and rename). If I call page1.php, the URL will display as page1.php. Everything is working fine while I try to log in or cause some errors. Now when I call index.php(which has the same code!), It htaccesshides index.phpin the URL how it should do! But when I test the login script, nothing will happen when submitting the form. It just updates the site. So I don’t know why this is happening?

This behavior will be triggered initially by htaccessrewriting rules. I uninstalled htaccessand tried again. Without it, it works, but still has those ugly URLs.

Good to show that in htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^.*\.html$ %1.php [L]  

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php

AddType application/x-httpd-php .htm .html

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteRule ^index\.(htm|html|php) http://www.domain.com/ [R=301,L]
## rewrite the index file in subdirectories
RewriteRule ^(.*)/index\.(htm|html|php) http://www.domain.com/$1/ [R=301,L]

and the form will be sent using:

form action = "<?php echo $_SERVER['PHP_SELF']?>" method= "post"...

So, if there is someone who could help me, I would really appreciate it.

UPDATE:

To provide additional information that I like:

First of all, the structure is as follows: due to different languages, the root structure is similar:

www.domain.com/languagefolder/...

, www.domain.com, languagesubfolder. , , www.domain.com/languagesfolder/index.php , www.domain.com/languagesfolder/. . . www.domain.com/languagesfolder/index.php www.domain.com/languagesfolder/, .../index.php. .

, , .../page .../page.php, . , : , , SQL-, , .../page.php, .../page.html .../page.htm.

+5
4

:

form action = "<?php echo $_SERVER['PHP_SELF']?>" method= "post"...

, , - :

form action = "/index.php" method = "post"...

. , :

RewriteRule ^index\.(htm|html|php) http://www.domain.com/ [R=301,L]

, index.php, , http://www.domain.com/ .

firefox firebug, , , . 301 POST/index.php, GET http://www.domain.com/.

, :

form action = "<?php echo $_SERVER['PHP_SELF']?>" method= "post"...

form action = "/" method= "post"...

form action = "<?php echo rtrim($_SERVER['PHP_SELF'], 'index.php'); ?>" method= "post"...

, str_replace, "index.php".

.

+4

.htaccess , . , URL (.. ), index.php . URL-, URL- (.. /, /index.php).

AddType .htaccess, .htm .html, URL-. *.index, , , ( .

.htaccess :

RewriteEngineOn
# redirect legacy index links. Do this first to clean up URL. No need to use full URL here unless directly to different domain
RewriteRule ^(.*)index\.(html|htm|php)$ /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php [L]
0

, , .htaccess. .

.htaccess:

RewriteEngine On
RewriteBase /stackoverflow/15032042

RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^.*\.html$ %1.php [L]  

# I don't understand this RewriteRule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php

AddType application/x-httpd-php .htm .html

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteRule ^index\.(htm|html|php)$ http://www.workspace.domain.tld/stackoverflow/15032042/ [R=301,L]
RewriteRule ^(.*)/index\.(htm|html|php) http://www.workspace.domain.tld/stackoverflow/15032042/$1/ [R=301,L]

index.php:

if(isset( $_POST))
    var_dump($_POST);
echo '<form action="" method="POST"><input type="hidden" name="test" value="1" /><input type="submit" /></form>';

, http://www.workspace.domain.tld/stackoverflow/15032042/ , $_POST .

, , RewriteBase?

0
source

To forward a query string, you need to add the QSA RewriteRule flag to the rule, or the query string will be discarded. In most cases, this is also good practice and helps to maintain your sanity, use a flag Lthat will prevent the processing of additional rules after the rule is executed. You really do not want to bind to several rules at the same time, instead, make separate rules 301and deal with redirects when they return.

RewriteRule ^(.*)$ $1.php [L,QSA]

Did this solve your problem?

NJoy!

0
source

All Articles