php - URL rewriting in .htaccess is causing HTTP request failed error
I am working on a php project where i am using .htaccess mod_rewrite to generate friendly urls for the website. I am working on local machine. Here are the urls,
http://localhost/sports/detail.php?Cat=cricket&Pro=ball
http://localhost/sports/list.php?Cat=cricket
I want these urls to look like following
http://localhost/sports/cricket/ball/
http://localhost/sports/cricket/
I wrote the following code in my .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule ([^/.]+)/([^/.]+)/?$ detail.php?Cat=$1&Pro=$2 [L]
</IfModule>
Now at this time every thing is working good. It is producing thehttp://example.com/sports/cricket/ball/
url. But when write rewrite rule forhttp://example.com/sports/cricket/
it is giving error. I am using this rewrite rule (same as previous url).
RewriteRule ([^/.]+)/?$ list.php?Cat=$1 [L]
This line is making apache very slow and at last it gives following error.
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
I changed rewrite rule asRewriteRule ([^/.]+)/ list.php?Cat=$1 [L]
. Now it's giving same error but this time it is recognizing the query string parameter.
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
I don't know where i am wrong in writing this rule.
Answer
Solution:
Extend your
rewrite
parameters: check if specified Url doesn't refer to existing file(directory) on your local server