URL错误.htaccess末尾的斜杠

时间:2014-07-21 06:57:54

标签: apache .htaccess

我的问题是,当我输入http://example.com/admin/时效果很好,$_GET['decode']包含正确的信息,我可以使用它。但是当我输入http://example.com/admin(没有斜线)时,我的网址重定向到http://example.com/admin/?decode=admin,一切都搞砸了。有人可以帮助我吗?

这是我的.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"

1 个答案:

答案 0 :(得分:2)

这是因为mod_dir/admin运行最后一条规则后,在目录URI(mod_rewrite)中添加了一个尾部斜杠。

试试这段代码:

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"
相关问题