Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 查询字符串的友好URL重写规则_Php_.htaccess_Mod Rewrite - Fatal编程技术网

Php 查询字符串的友好URL重写规则

Php 查询字符串的友好URL重写规则,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我想重写htaccess以接受搜索引擎优化友好的查询字符串 我用来通过url传递参数的旧方法是: http://sitename.com/foldername/edit-agent.php?name=John-Smith 我想将上述url更改为: http://sitename.com/foldername/edit-agent/John-Smith 我的htaccess文件规则如下所示: <files page> ForceType application/x-httpd-ph

我想重写htaccess以接受搜索引擎优化友好的查询字符串

我用来通过url传递参数的旧方法是:

http://sitename.com/foldername/edit-agent.php?name=John-Smith
我想将上述url更改为:

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>
当我到达url时http://sitename.com/foldername/edit-agent/John-Smith,页面显示内部服务器错误

这件事有什么线索吗?

试试这个:

Options +FollowSymLinks 
RewriteEngine on  
RewriteRule (.*)/ edit-agent.php?name=$1
将此代码保存在/foldername/.htaccess中:


RewriteCond%{ENV:REDIRECT_STATUS}^$将阻止重写规则执行多次。

您的规则中是否遗漏了foldername?
Options +FollowSymLinks 
RewriteEngine on  
RewriteRule (.*)/ edit-agent.php?name=$1
<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>