[英]Friendly URL rewrite rules for query string
I wanted to rewrite htaccess to accept query string for SEO friendly, 我想重写htaccess以接受对SEO友好的查询字符串,
The old method that I used to passing parameters through url is: 我用来通过url传递参数的旧方法是:
http://sitename.com/foldername/edit-agent.php?name=John-Smith
I wanted to change above url to: 我想将上述网址更改为:
http://sitename.com/foldername/edit-agent/John-Smith
my htaccess file rule is as follow: 我的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>
to get the passing parameter, in edit-agent.php
file, I use: 为了获得传递的参数,在edit-agent.php
文件中,我使用:
$agent_name = preg_replace('/[^a-zA-Z]/', '', $mysqli->real_escape_string($_GET['name']));
When I got to url http://sitename.com/foldername/edit-agent/John-Smith
, the page is show Internal Server Error 当我进入url http://sitename.com/foldername/edit-agent/John-Smith
,页面显示为Internal Server Error
any clue on this matter? 关于这件事有什么线索吗?
Try this: 尝试这个:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)/ edit-agent.php?name=$1
Keep this code in /foldername/.htaccess
: 将此代码保存在/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} ^$
will prevent rewrite rules to execute more than once. RewriteCond %{ENV:REDIRECT_STATUS} ^$
将阻止重写规则执行多次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.