.htaccess
就像火箭科学一样(我想我不是唯一一个)。我正在尝试创建一些RewriteRule
来美化我的网址。
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
等网址自动成为/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
错误文档。
我让我疯了,因为我希望这个网址: http://localhost/students/?show_profile=123#photos
为 http://localhost/students/123/#photos
(等等其他网址)
我的问题
.htaccess
文件应该怎么样?.htaccess
?答案 0 :(得分:1)
重新排列规则,使用选项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]