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
Related
I know my question is asked many times but unfortunately I could't find my answer. Maybe because I don't put the .htaccess file in the correct place.
What I want is to redirect http://mail.example.com , https://mail.example.com to https://example.com.
I also wanted to redirect https://www.example.com , http://example.com, http://www.example.com to https://example.com. I did this job with adding below code in .htaccees file in public_html in cpanel and it works.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
I used below code from this link and put .htaccess file in mail folder. but when I type http://mail.example.com it redirects to https://mail.example.com and https://mail.example.com also doesn't go to http://example.com. Maybe the problem is with https.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mail\.mysit\.com [NC]
RewriteRule ^(.*) https://example.com/$1 [L,R=301]
Any help is appreciated.
p.s. My site is designed with joomla and there is no redirection in cpanel and joomla settings.
I think everything is correct, and that 'it's only a matter of order:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mail\.example\.com [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
In you main .htaccess file
I want to redirect all the urls of a directory (example.com/blog/urlnames) on one domain to a sub-domain (blog.example.com/urlnames)
I tried:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^/blog$ [NC]
RewriteRule (.*) https://blog.example.com/$1 [R=301,L]
I keep getting a 404 error when I type the url on example.com:
https://example.com/blog/5-names-for-actors/
I want this to go to:
https://blog.example.com/5-names-for-actors/
You can use this rule in blog/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule (.*) https://blog.example.com/$1 [R=301,L,NE]
File blog/.htaccess may not be existing already so you may have to create it.
I'm trying to setup a redirect for a site.
I want rewrite file requests from a folder to a subdomain url.
At the moment, I have this in my htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{HTTP_HOST} !^example.com
RewriteCond %{HTTP_HOST} ^g.example.com
RewriteRule ^(uploads/(.*)+ uploads/%1%{REQUEST_URI} [L]
The idea is that when a visitor requests:
http://g.example.com/uploads/somefile.png
they are served:
http://example.com/uploads/somefile.png
So it's working as expected. However the problem is that:
http://b.example.com/uploads/somefile.png
also works.
I only want http://g.example.com/ to be rewritten. http://b.example.com/ should 404.
This should work:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^g.example.com$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*)\.(JPG|GIF|PNG) [NC]
RewriteRule ^ - [R=404,L]
RewriteCond %{HTTP_HOST} ^g.example.com$ [NC]
RewriteCond %{THE_REQUEST} !^GET [NC]
RewriteRule ^ - [R=404,L]
The first rule will make sure that any URL ending with JPG, GIF, PNG that does not come from g.example.com send a 404 not found request to the user.
The second rule makes sure that g.example.com are only accessed using GET requests.
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.
I currently use the following redirect to make the urls look nicer:
RewriteRule profile/(.*) index.php?id=$1
(Result: domain.co.uk/profile/00000001)
From index.php?id=00000001
I would like to 301 redirect urls without www to www. and keep the above profile redirect.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
However, When this is used the URL comes out like:
http://www.DOMAIN.co.uk/ index.php /00000001 ?id=00000001
I’m assuming this can be done, Does this need to be bespoke for my needs or is there something im missing?
End result would ideally rewrite:
domain.co.uk/profile/00000001
to
www.domain.co.uk/profile/00000001
Keep rules in correct order i.e. keep external redirects before your internal rewrites.
So this should work:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^profile/(.+)$ index.php?id=$1 [L,QSA,NC]