我想重写htaccess以接受SEO友好、的查询字符串
我用来通过url传递参数的旧方法是:
http://sitename.com/foldername/edit-agent.php?name=John-Smith
我想把上面的网址改成:
http://sitename.com/foldername/edit-agent/John-Smith
我的htaccess文件规则如下:
<files page>
ForceType application/x-httpd-php
</files>
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^edit-agent/([^/'.]+)/?$ edit-agent.php?name=$1 [L]
#resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME}'.php -f
RewriteRule ^(.*)$ $1.php [L]
</IfModule>
为了获得传递参数,在edit-agent.php
文件中,我使用:
$agent_name = preg_replace('/[^a-zA-Z]/', '', $mysqli->real_escape_string($_GET['name']));
当我到达url http://sitename.com/foldername/edit-agent/John-Smith
时,页面显示内部服务器错误
这件事有线索吗?
将此代码保存在/foldername/.htaccess
:中
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch -MultiViews
RewriteEngine On
RewriteBase /foldername/
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^edit-agent/([^/.]+)/?$ edit-agent.php?name=$1 [L,QSA]
#resolve .php file for extensionless php urls
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME}'.php -f
RewriteRule ^(.*)$ $1.php [L]
</IfModule>
RewriteCond %{ENV:REDIRECT_STATUS} ^$
将阻止重写规则执行多次。
试试这个:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)/ edit-agent.php?name=$1