繁体   English   中英

.htaccess中的URL重写导致HTTP请求失败错误

[英]URL rewriting in .htaccess is causing HTTP request failed error

我正在一个PHP项目中,在这里我使用.htaccess mod_rewrite为网站生成友好的URL。 我正在本地机器上工作。 这是网址

http://localhost/sports/detail.php?Cat=cricket&Pro=ball
http://localhost/sports/list.php?Cat=cricket

我希望这些网址看起来像以下

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>

现在,此时一切正常。 它正在生成http://example.com/sports/cricket/ball/网址。 但是,当对http://example.com/sports/cricket/写入重写规则时,它给出了错误。 我正在使用此重写规则(与以前的URL相同)。

RewriteRule ([^/.]+)/?$ list.php?Cat=$1 [L]

此行使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

我不知道我在写这条规则时哪里错了。

扩展您的rewrite参数:检查指定的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM