url not redirecting in chrome - .htaccess

I put a 301 redirect code in htaccess. When I try to access the old url it redirects to new url without any problem in Firefox but in Chrome it is not redirecting.
Is it the problem with the htaccess code or some other problem.
I have cleared Chrome cache number of times but still no luck.
Final htaccess code is
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.herotscareers.co.uk
RewriteRule (.*) http://www.webhelptsccareers.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^herotscareers.co.uk
RewriteRule (.*) http://www.webhelptsccareers.com/$1 [R=301,L]
RedirectMatch 301 ^.+$ /
www.herotscareers.co.uk or herotscareers.co.uk is redirecting to http://www.webhelptsccareers.com without any problem but http://www.webhelptsccareers.com/anyfolder/ is not redirecting to http://www.webhelptsccareers.com

Replace your 3 rules with this single rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.webhelptsccareers\.com$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/.
RewriteRule ^ http://www.webhelptsccareers.com/ [R=301,L]
Clear your browser cache and retest.

Related

.htaccess redirect not directing to specified file

I have an .htaccess file on an old domain of mine that includes redirects that aren't redirecting as I am wanting.
If I type in olddomain.com/about-us.html the redirect is sending the user to newdomain.com/about-us.html. What I am trying to do is direct the user to newdomain.com/about.
Below is my .htaccess file with one example of the redirect.
Does anyone see what I am doing wrong?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} !/administrator [NC]
RewriteRule /about-us.html https://newdomain.com/about [L,R=301]
Redirect 301 /about-us.html https://newdomain.com/about
RewriteRule ^ https://newdomain.com%{REQUEST_URI} [L,R=301,NE]
Network Tab:
Have it like this:
RewriteEngine On
RewriteRule ^about-us\.html$ https://newdomain.com/about [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteCond %{THE_REQUEST} !/administrator [NC]
RewriteRule ^ https://newdomain.com%{REQUEST_URI} [L,R=301,NE]
Make sure to test it in a new browser or completely clear browser cache.
Make sure there is no other code in your .htaccess when you test

.htaccess 301 Redirect Except Main Page for .html

I'm trying to redirect all URLs in www.oldexample.com/index.html to www.newexample.com/index.html except the homepage (www.oldexample.com/index.html).
I have tried this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.oldexample\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?$ [NC]
RewriteRule ^(.*)$ http://www.newexample.com/$1 [R=301,L]
but it didn't work. It is redirecting all pages.
How can I make it work?
Please try with below,
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html
RewriteRule ^(.*)$ http://www.newexample.com/$1 [R=301,L]

.htaccess not redirecting from old url to new url

i have developed a website using codeigniter. Previously the site had a long URL structure so i have made them shorter in the new website.
Although i used the redirect directive in htaccess it gives me a 404 error. I have removed all the old controllers and functions.
below is a few lines from htaccess (there are many urls redirecting to new ones)
RewriteEngine On
# Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
#RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Redirect 301 /payments/charity_and_donations/paid http://www.mysite.com/charity
Redirect 301 /outwards/office_furniture/damaged http://www.mysite.com/office_assets
Redirect 301 /funding/business_and_person/inward http://www.mysite.com/funds
can someone tell me why it is not redirecting from the old to the new and what am i doing wrong?
You need to have your redirecting happen before you route URIs to /index.php. Also, since Redirect is part of mod_alias and your other redirect/routing rule is mod_rewrite, the URI is being processed twice when it's not supposed to. You should just use mod_rewrite and add the rules to the beginning:
RewriteEngine On
# Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
RewriteRule ^payments/charity_and_donations/paid http://www.mysite.com/charity [R=301,L]
RewriteRule ^outwards/office_furniture/damaged http://www.mysite.com/office_assets [R=301,L]
RewriteRule ^funding/business_and_person/inward http://www.mysite.com/funds [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Try the below code, this works perfectly for me
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]

Htaccess does not redirect non-root pages

Case:
www.domain.com redirects to domain.com
www.domain.com/somecategory does not redirect to domain.com/somecategory.
The links on the page are relative, and this is causing problems with google as all www links are now duplicate content. Is there any way to fix this and force a non-www redirect on all WWW pages regardless of if it's root or not ?
htaccess:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1$1 [R=301,L]
i've also tried
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
I have changed your code to:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
And it seems to be working.
Without the slash in the rewrite rule, I was redirected to domain.compage instead of domain.com/page

Htaccess redirecting non-www to www

I have searched the web all over for a good generic .htaccess script for redirecting non-www to www, and currently i'm using this:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
This works fine, but if i go to a subdomain www. will be added. Does anyone has a good working redirect .htaccess script?
Try this :
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^([^\.]+)\.([^\.]+)\.([a-z]{2,4})$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
#Vince What if the requested url is something like:
http://www.abc.example.com
IMHO, I think with your method it would never be redirected to:
http://www.example.com
How about this?
# Rewrite domain
RewriteCond %{HTTP_HOST} !^www\.([a-z1-9\-]+)\.([a-z]+)$ [NC] [and]
RewriteCond %{HTTP_HOST} ([a-z1-9\-]+)\.([a-z]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1.%2/$1 [R=301,L]
Also, you guys may find these references useful:
https://www.drupal.org/node/93603
http://www.askapache.com/htaccess/modrewrite-tips-tricks.html

Resources