我的网址已重写,删除.php并替换为/
目前.htaccess看起来像这样 -
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
虽然现在,我正在尝试传递GET参数,
当我将其添加到.htaccess -
时RewriteRule ^(.*)$ public_profile.php?params=$1 [NC]
或者
RewriteRule ^(.*)$ public_profile/params=$1 [NC]
导航到localhost / pages / public_profile / myparam
我收到内部服务器错误。
我还尝试将.htaccess放在pages / public_profile目录的旁边
RewriteEngine On
RewriteRule ^(.*)$ index.php?params=$1 [NC]
当我导航到http://localhost/pages/public_profile/
时并打印$ _GET," index.php"打印
任何人都可以指出我做错了吗?
答案 0 :(得分:1)
有一个单独的规则来处理get参数:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?params=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]