Reputation: 2484
I want to use apache rewrite module to do complex rewriting.
For example If the url is http://www.site.com/wall and http://www.site.com/profile and http://www.site.com/info I want to rewrite into http://www.site.com/gotopage.php?page=wall ,or http://www.site.com/gotopage.php?page=profile and so forth
But if the url is other than that I want to pass it the other way For example. if the url is http://www.site.com/newthing then it should rewrite as http://www.site.com/index.php?params=newthing
Please Help. I tried to see other questions but did not get it!
Upvotes: 0
Views: 188
Reputation: 219938
RewriteEngine On
# Special rule for 3 unique cases
RewriteRule /(wall|profile|info)$ /gotopage.php?page=$1 [L]
# Only rewrite if the URL has not yet been rewritten
RewriteCond %{HTTP_URL} (?!gotopage\.php|index\.php)
RewriteRule /([^/]+) /index.php?params=$1 [L]
Here's an explanation, line by line:
Any URL that matches one of the 3 specified words gets rewritten to go to gotopage.php
.
This line is a condition for the next line. Only if the URL matches this regex will the next line even be considered. The regex checks to ascertain that the request is not already going to gotopage.php
or index.php
. If it is, we don't want to rewrite anything (we would just end up in an infinite loop).
If the requested URL has no subsequent slashes, rewrite it to go to index.php
.
Upvotes: 2