Mobile app version of vmapp.org
Login or Join
Deb1703797

: Htacess seems to make the page load forever 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

@Deb1703797

Posted in: #Htaccess #Php #WebHosting

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= [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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Deb1703797

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

RewriteRule ^.*$ index.php?page= [NC,L]


This will result in a rewrite loop. You are also not capturing the sub pattern, so 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= [NC,L]


Only when the request is not for /index.php will the RewriteRule be processed. The parenthesised sub pattern (.*) is stored in .

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme