Page 1 of 1

RegExp and Apache RewriteEngine (missing www.)

Posted: Thu Feb 09, 2006 10:33 am
by visionmaster
Hello together,

I would like to use Apaches mod_rewrite to redirect from http://webpage.com to http://www.webpage.com

The URL path may ofcourse hold a path of folders and some further parameters like so: http://webpage.com/folder1/folder2/mysr ... tion=start

RewriteCond %{HTTP_HOST} ^\.webpage\.com seems to be a good start. But how do I actually form the RewriteRule? I need to get hold of REQUEST_URI and QUERY_STRING (which can be empty or not). Howto?




Thanks,
visionmaster

Posted: Thu Feb 09, 2006 5:20 pm
by pickle
What about something like:

Code: Select all

RewriteRule /^webpage.com(.*)$/ www.webpage.com$1
This is untested of course ubt does the idea make sense?

Posted: Thu Feb 09, 2006 5:34 pm
by josh
I don't think regex let's you get at the absolute URLs in that manner, why not set up two Virtual hosts, one for www. and one without, have the one without just have an index.php that outputs a permanently moved header to redirect to the www. version

Posted: Thu Feb 09, 2006 5:37 pm
by feyd
it does allow you to do it, indirectly..

Code: Select all

RewriteEngine on
RewriteCond %{HTTP_HOST} ^webpage.com$
RewriteRule /(.*) http://www.webpage.com/$1
not tested, but from memory.. may be a tiny bit off.

Posted: Sat Feb 11, 2006 5:01 am
by visionmaster
feyd wrote:it does allow you to do it, indirectly..

Code: Select all

RewriteEngine on
RewriteCond %{HTTP_HOST} ^webpage.com$
RewriteRule /(.*) http://www.webpage.com/$1
not tested, but from memory.. may be a tiny bit off.
@feyd thanks for your help, I was thinking much to complicated. It works like this:

Code: Select all

RewriteEngine on
RewriteCond %{HTTP_HOST} ^webpage.de$
RewriteRule (.*) http://www.webpage.de/$1

Thanks to you all!