Reputation: 2683
My problem is, when I enter http://example.com/admin/
it works well, $_GET['decode']
contains right information and I can work with it. But when I enter http://example.com/admin
(without slash), my URL redirects to http://example.com/admin/?decode=admin
and everything is messed up. Could someone helps me?
Here is my .htaccess
:
RewriteEngine on
Options +FollowSymlinks
<FilesMatch "(config.php|defines.php|functions.php)">
Order Allow,Deny
Deny from all
</FilesMatch>
Header set X-UA-Compatible "IE=Edge,chrome=1"
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([^\.]+)$ ./index.php?decode=$1 [L,QSA]
php_value date.timezone "Europe/Bratislava"
Upvotes: 1
Views: 444
Reputation: 785196
It is because mod_dir
is adding a trailing slash in the directory URI (/admin
) after your last rule is run by mod_rewrite
.
Try this code:
DirectorySlash Off
RewriteEngine on
Options +FollowSymlinks
<FilesMatch "(config.php|defines.php|functions.php)">
Order Allow,Deny
Deny from all
</FilesMatch>
Header set X-UA-Compatible "IE=Edge,chrome=1"
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,NE,L]
## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \s/+(.*?)[^/][?\s]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ ./index.php?decode=$1 [L,QSA]
php_value date.timezone "Europe/Bratislava"
Upvotes: 2