[英]htaccess rewrite rule fails
.htaccess
对我来说就像是火箭科学(我想我不是唯一的人)。 我正在尝试创建一些RewriteRule
来美化我的URL。
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
RewriteRule (.*)/$ $1.php [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]
RewriteRule ^download/(.*)/$ /download.php?fid=$1 [L]
RewriteRule ^students/(.*)/ /students.php?show_profile=$1 [L]
PHP重定向效果很好(我的意思是,像/students.php
这样的URL会自动变为/students/
)。 现在,我特别对这两行感兴趣:
RewriteRule ^download/(.*)/$ /download.php?fid=$1 [L]
RewriteRule ^students/(.*)/ /students.php?show_profile=$1 [L]
所以,当我写:
http://localhost/students/123
它成为了:
http://localhost/C:/xampp/htdocs/students/123/
我得到一个403
错误文档。
我发疯了,因为我希望该URL: http://localhost/students/?show_profile=123#photos
成为http://localhost/students/123/#photos
(其他URL依此类推)
我的问题
.htaccess
文件应该看起来如何? .htaccess
? 重新排列规则,使用选项MultiViews
并修复URI模式中的一些正则表达式。
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301,NE]
RewriteRule ^download/(.*)/$ download.php?fid=$1 [L,QSA]
RewriteRule ^students/(.*)/ students.php?show_profile=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.