View Full Version : Mod rewrite for GET variable
TheBlueblib
01-01-2010, 03:30 PM
I would greatly appreciate if someone could help me on this. I have a site www.example.com, and I use it to pass URL's as variables. For example:
http://www.example.com/http://bbc.co.uk
How can I rewrite the url using mod_rewrite so that it looks like this:
http://www.example.com/bbc.co.uk
In other words, remove the second 'http://'.
itsallkizza
01-04-2010, 04:01 PM
If you want "http://www.example.com/bbc.co.uk" to actually display the page that lies at "http://www.example.com/http://bbc.co.uk" then you can try something like this:
RewriteEngine on
RewriteBase /
RewriteRule ^/(.*)$ $1 [qsa,L]
The above won't work on all configurations though because it may treat it like an absolute url. I strongly recommend using a virtual sub directory and a GET variable for the appended url, like this:
RewriteRule ^/(.*)$ do-something/?url=$1 [qsa,L]
Using a sub directory is more modular allowing for easy future functional changes and opens up the opportunity to more easily create other root directory pages for your site, such as a home page or about section. It's also more descriptive/semantic which makes for better SEO.
You can replace "(.*)" with a more specific definition to suit your needs. For example, if you only want to run this rule on urls with a second "http://" you can do something like:
RewriteRule ^/http://(.*)$ do-something/?url=$1 [qsa,L]
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.