Jump to content
Sign in to follow this  

Rule being ignored

Recommended Posts

Hi there,

  My htaccess is ignoring one of the rules I have put in! I don't imagine I am blameless here, so am hoping someone can point out what I have done wrong and how to fix it. The lines in bold (forwarding the non www request to the address with the www) seems to be failing. I tried re-ordering the rules, but no joy as yet. 

If someone could help me as to what needs amending here I would be really appreciative. Thanks!


<IfModule mod_rewrite.c>

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.co.uk$
RewriteRule (.*)$ http://www.newsite.co.uk/$1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC]

RewriteCond %{HTTP_HOST} ^newsite.co.uk$
RewriteRule (.*) http://www.newsite.co.uk/$1 [R=301]

Redirect 301 /oldpage http://www.newsite.co.uk

Share this post

Link to post
Share on other sites

It would be a good idea to explain the solution you proposed, otherwise nothing will be learned. 

If I'm remembering correctly, the NC flag makes the rule case-insensitive. 

Share this post

Link to post
Share on other sites

Well, I was just offering a quick solution to try. 

I would comment out all the rewrite conditions and rules that are not of concern at first and work only with the non www to www. Although the poster mentioned re-ordering the rules and still not working, commenting out the other rules for testing the condition and rule you want is helpful in isolating incase any of the other conditions and rules are conflicting somehow. 

I see that the poster does not have ^ and  $ for the RewriteRule for (.*). This may or may not be the the issue but from my understanding it's good practice to have in the rewrite rule the beginning(^) and end indicators($).

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...