homepage Welcome to WebmasterWorld Guest from 54.234.0.85
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Rewrite conditional on server
only rewrite rules if specific server
Tourex

10+ Year Member



 
Msg#: 4174118 posted 3:40 pm on Jul 21, 2010 (gmt 0)

I develop sites on a Windows machine running LAMP under WampServer. The final sites run on a Linux server. Obviously I want my development environment to match the live environment as closely as possible.

One of the problems I have is that I have been unable to use the same .htaccess file because of the following rule:

### re-direct non-www to www
RewriteCond %{http_host} !^www.mydomain.com$ [nc]
RewriteRule ^(.*)$ [mydomain.com...] [r=301,nc,L]
####

Not being able to use the same .htaccess file is causing me severe problems because of other issues. Is there ANY way to make the above rule conditional on the server type?

The URL of the development site is of format [localhost...] I basically don't want to run the above rewrite if the URL includes /localhost/ (or if the server type is Windows, I guess).

Any help would be much appreciated.

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4174118 posted 7:00 am on Jul 23, 2010 (gmt 0)

How about:

# externally redirect non-blank non-canonical hostname to canonical hostname
# (also exclude "localhost" and entire non-routable loopback IP address range)
RewriteCond %{HTTP_HOST} !^(www\.example\.com|localhost|127(\.[0-9]{1,3}){3})?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Jim

Tourex

10+ Year Member



 
Msg#: 4174118 posted 11:18 am on Jul 26, 2010 (gmt 0)

Thanks Jim, but sadly doesn't seem to work. It is correctly excluding the rewrite when the site is accessed from the Windows development site, but it not rewriting mydomain.com to www.mydomain.com.

Any thoughts please?

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4174118 posted 1:53 pm on Jul 26, 2010 (gmt 0)

I'm not sure how you tested, so I can't really interpret your results...

But make sure that the "www\.example\.com" pattern in the RewriteCond and the "www.example.com" in the RewriteRule substitution URL match exactly, except for the escaping required in the RewriteCond pattern, and be sure to always delete your browser cache before testing any new server-side code.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved