Php 在.htaccess中重写URL导致HTTP请求失败错误
我正在从事一个php项目,我正在使用.htaccess mod_rewrite为网站生成友好的URL。我在本地机器上工作。这里是网址Php 在.htaccess中重写URL导致HTTP请求失败错误,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我正在从事一个php项目,我正在使用.htaccess mod_rewrite为网站生成友好的URL。我在本地机器上工作。这里是网址 http://localhost/sports/detail.php?Cat=cricket&Pro=ball http://localhost/sports/list.php?Cat=cricket 我希望这些URL如下所示 http://localhost/sports/cricket/ball/ http://localhost/sports/cr
http://localhost/sports/detail.php?Cat=cricket&Pro=ball
http://localhost/sports/list.php?Cat=cricket
我希望这些URL如下所示
http://localhost/sports/cricket/ball/
http://localhost/sports/cricket/
我在.htaccess文件中编写了以下代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule ([^/.]+)/([^/.]+)/?$ detail.php?Cat=$1&Pro=$2 [L]
</IfModule>
这一行使apache非常慢,最后它给出了以下错误
Warning: file_get_contents(http://localhost/Sports/api/v1/list_one.php?Cat=php): failed to open stream: HTTP request failed! in C:\xampp\htdocs\Sports\list.php on line 5
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\Sports\list.php on line 5
我将重写规则更改为RewriteRule([^/]+)/list.php?Cat=$1[L]
。现在它给出了相同的错误,但这次它识别了查询字符串参数
Warning: file_get_contents(http://localhost/Sports/api/v1/list_one.php?Cat=cricket): failed to open stream: HTTP request failed! in C:\xampp\htdocs\Sports\list.php on line 5
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\Sports\list.php on line 5
我不知道我写这条规则的地方错了。扩展您的
重写
参数:检查指定的Url是否未引用本地服务器上的现有文件(目录)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index\.php$ - [L]
RewriteRule ([^/]+)/([^/]+)/?$ detail.php?Cat=$1&Pro=$2 [L]
</IfModule>
重新启动发动机
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index\.php$-[L]
重写规则([^/]+)/([^/]+)/?$detail.php?Cat=$1&Pro=$2[L]
扩展您的重写
参数:检查指定的Url是否未引用本地服务器上的现有文件(目录)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index\.php$ - [L]
RewriteRule ([^/]+)/([^/]+)/?$ detail.php?Cat=$1&Pro=$2 [L]
</IfModule>
重新启动发动机
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index\.php$-[L]
重写规则([^/]+)/([^/]+)/?$detail.php?Cat=$1&Pro=$2[L]
您需要从PHP端进行调试,以确定意外输入是什么。您需要从PHP端进行调试,以确定意外输入是什么。