htacess seems to make the page load forever
htacess seems to make the page load forever -
Solution :
Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about web-hosting, php, htaccess, , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :I need to rewrite a URL of my server so the URL looks friendly. Like:
site.com/var1/var2/var3/...
to
site.com/index.php?page=var1/var2/var3/...
So I wrote this .htacess:
RewriteEngine On
RewriteRule ^.*$ index.php?page=$1 [NC,L]
But when I upload it to the server, and try to load a page, the page loads forever! What am I doing wrong?
RewriteRule ^.*$ index.php?page=$1 [NC,L]
This will result in a rewrite loop. You are also not capturing the sub pattern, so $1 will be empty. In order to prevent a rewrite loop, you need a get-out-clause, such as not rewriting when the request is already for index.php.
Something like:
RewriteEngine On
RewriteCond %REQUEST_URI !=/index.php
RewriteRule ^(.*)$ /index.php?page=$1 [NC,L]
Only when the request is not for /index.php will the RewriteRule be processed. The parenthesised sub pattern (.*) is stored in $1.
Comments
Post a Comment