Jump to content

Rule being ignored


ben03

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

Link to comment
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. 

Link to comment
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($).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...