lundi 20 avril 2015

Forms not working after .htaccess URL rewrite

I copied the below code from some other posts. It successfully helped me to stripped the .php extension from the URL. However, after implementing this, some of my forms are no longer working. I have forms that are posting like

<form method='post' action='/users/activate/Qwerty'></form>

Now it is not sending the data to the location when I submit the form. I realize that if I change the action='/users/activate/Qwerty' to action='?action=activate&code=Qwerty123', the forms will work again. But there are a number of pages that contain forms posting to different locations in my website, and I do not want to change so many of them manually. So I wouold like to know why the data are not posting as expected and how can I solve the problem?

My .htaccess is below

#the line below will hide folders and their contents on any apache server. Use 'Options +Indexes' to unhide
Options -Indexes

#the line below will hide folders and their contents on goDaddy. Use 'Options +MultiViews' to unhide
Options -MultiViews

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#maintain post data after rewrite
RewriteCond %{REQUEST_METHOD} =POST


# Force WWW prefix
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]+)\.([a-z]{2,4})$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


# Remove .php extension
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]

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


# Force trailing slash
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]   

RewriteCond %{REQUEST_URI} ^/users/([A-Za-z0-9-]+)/?$
RewriteRule ^users/(.*)/?$ /users.php?action=$1 [QSA,NC,L]
RewriteRule ^users/([A-Za-z0-9-]+)/([A-Za-z0-9-,=]+)/?$  /users.php?action=$1&code=$2 [QSA,NC,L]



#the lines below relocate all 404 to the index page
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)?$ /index.php [NC,L]

</IfModule>

Aucun commentaire:

Enregistrer un commentaire