Rewrite Rules for non-www to www redirects to IP address

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

Rewrite Rules for non-www to www redirects to IP address

Postby paulseatonsmith » Tue Jan 03, 2012 1:48 pm

I have the following in .htaccess in apache2/htdocs

Options +Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.rightsizesolutions\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.rightsizesolutions.co.uk/$1 [L,R=301]

but when I type -rightsizesolutions.co.uk into a browser it resolves to the servers IP address rather than -http://www.rightsizesolutions.co.uk

What am I doing wrong?
paulseatonsmith
 
Posts: 4
Joined: Tue Jan 03, 2012 1:42 pm

Advertisement

Re: Rewrite Rules for non-www to www redirects to IP address

Postby Stephen26 » Tue Jan 03, 2012 1:58 pm

I install and configure phpBB-SEO (and other mods) for a fair price and very fast. If you are interested simply send me a private message.
Stephen26
phpBB SEO Team
phpBB SEO Team
 
Posts: 434
Joined: Mon May 03, 2010 7:06 am

Re: Rewrite Rules for non-www to www redirects to IP address

Postby paulseatonsmith » Tue Jan 03, 2012 2:36 pm

Amazing - thank you so much for the quick response.

In case anyone else comes across this I had to change my .htaccess files (I have a few) from

Options +Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^-www\.rightsizesolutions\.co.uk$ [NC]
RewriteRule ^(.*)$ -http://www.rightsizesolutions.co.uk/$1 [L,R=301]

to

Options +Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^-www\.rightsizesolutions\.co.uk$ [NC]
RewriteCond %{HTTP_HOST} ^176\.34\.235\.230 [NC]
RewriteRule ^(.*)$ -http://www.rightsizesolutions.co.uk/$1 [L,R=301]

and it works fine now (note you have to remove '-' from the front of URLS as I cannot post URLs on this forum)
paulseatonsmith
 
Posts: 4
Joined: Tue Jan 03, 2012 1:42 pm

Re: Rewrite Rules for non-www to www redirects to IP address

Postby paulseatonsmith » Wed Jan 04, 2012 10:18 am

Well I spoke to soon.

Doesn't seem to work properly on IE - some images are not displayed correctly when accessing without the www.

Is my syntax correct?
paulseatonsmith
 
Posts: 4
Joined: Tue Jan 03, 2012 1:42 pm

Re: Rewrite Rules for non-www to www redirects to IP address

Postby Stephen26 » Wed Jan 04, 2012 10:37 am

You have to change rightsizesolutions\.co.uk to rightsizesolutions\.co\.uk and use [OR,NC]

Code: Select all
RewriteCond %{HTTP_HOST} ^example\.com [OR,NC]
RewriteCond %{HTTP_HOST} ^123\.45\.67\.89
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Another approach:

RewriteCond %{HTTP_HOST} ^(example\.com|123\.45\.67\.89) [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


http://stackoverflow.com/questions/6918 ... -or-and-nc
I install and configure phpBB-SEO (and other mods) for a fair price and very fast. If you are interested simply send me a private message.
Stephen26
phpBB SEO Team
phpBB SEO Team
 
Posts: 434
Joined: Mon May 03, 2010 7:06 am

Re: Rewrite Rules for non-www to www redirects to IP address

Postby paulseatonsmith » Wed Jan 04, 2012 12:51 pm

Thanks

Finally got it working..

I think it was confused by further URL rewriting rules before it so I put it to the top of .htaccess

Code: Select all
Options +Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.rightsizesolutions\.co.uk$ [OR,NC]
RewriteCond %{HTTP_HOST} ^176\.34\.235\.230 [NC]
RewriteRule ^(.*)$ http://www.rightsizesolutions.co.uk/$1 [L,R=301]
paulseatonsmith
 
Posts: 4
Joined: Tue Jan 03, 2012 1:42 pm

Re: Rewrite Rules for non-www to www redirects to IP address

Postby Stephen26 » Wed Jan 04, 2012 12:57 pm

Ok, great that it's finally working!
I install and configure phpBB-SEO (and other mods) for a fair price and very fast. If you are interested simply send me a private message.
Stephen26
phpBB SEO Team
phpBB SEO Team
 
Posts: 434
Joined: Mon May 03, 2010 7:06 am

Re: Rewrite Rules for non-www to www redirects to IP address

Postby luhar1010 » Fri Jan 18, 2013 5:24 am

Comment: Thank you so much guys for the quick response. This problem of unwanted redirect had been plaguing me for some time. The fix worked perfectly for me. As far as IE is concerned, I haven’t used it in ages and so it is not of a concern for me.
luhar1010
 
Posts: 1
Joined: Thu Jan 17, 2013 11:13 am

Re: Rewrite Rules for non-www to www redirects to IP address

Postby brandon790 » Tue Apr 15, 2014 10:47 pm

How do I do a IP rewrite for citrix ICA file using Apache HTPP Server 2.2? I have client who are on an external network who can access the proxy server IP for example 10.33.71.27 and launch and login into Citrix. However, they do not have access to Server where the ICA file is located on the internal network. I need to know how to rewrite 10.33.69.101:1494 [external user do not have access] to 10.33.71.27:1494 so that the ICA file can be downloaded from the users Citrix session on the external network.
any assistance or feedback will be greatly appreciated. thanks.
brandon790
 
Posts: 1
Joined: Tue Apr 15, 2014 10:33 pm


Return to Apache mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 1 guest