Got a .htaccess file that is working correctly with the following
Redirect 301 /secure/test/ http://ww2.example.com/secure/test/
Redirect 301 /test/ http://ww2.example.com/test/
Redirect 301 /submission/ http://ww2.example.com/submission/
That will happily redirect:
http://example.com/secure/test/login.aspx
However if someone comes in on
https://example.com/secure/test/login.aspx
It doesn't work, how to I also redirect all https traffic to follow the rules above?
You will need to change your mod_alias redirects to use mod_rewrite instead.
For example, in .htaccess:
RewriteEngine
RewriteCond %{SERVER_PROTOCOL} ^http(s?) [NC]
RewriteRule ^(secure/test/.*) http%1://ww2.example.com/$1 [R=302,L]
This redirects http to http and https to https. (Are you sure you don't always want to redirect to https instead?)
The %1 backreference matches the s in the SERVER_PROTOCOL (if present).
Clear your browser cache before testing (301 redirects are cached), and change the 302 (temporary) redirect to 301 (permanent) when you are sure it's working OK.
Related
My old blog URL is http://www.blog.example.com/
My new blog URL is https://example.com/
I want to know how can I redirect all my old blog URLs to my new blog URLs.
For example, I want to redirect this URL:
http://www.blog.example.com/excellent-examples-forms-web-design
to
https://example.com/excellent-examples-forms-web-design
You can do this using mod_rewrite in .htaccess. mod_rewrite is required in order to check the requested hostname.
For example, at the top of your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.blog\.(example\.com) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
The %1 backreference matches example.com in the preceding CondPattern (this simply saves repetition).
Test first with a 302 (temporary) redirect and change to a 301 (permanent) redirect when you are sure it's working OK - to avoid potential caching issues.
I've finished a website, now i'm changing old website to new and creating 301 redirects in .htaccess.
I have a sitemap containing aroud 100 equal get requests like:
?foodmenu=name-of-the-dish
In the new website there is no similar request and all this requests must be redirected to a fixed website, lets say http://myrestaurant.com/menu
There is a way I can avoid 100+ lines of almost similar httacces lines:
Instead of:
Redirect 301 ?foodmenu=name-of-the-dish1 http://myrestaurant.com/menu
Redirect 301 ?foodmenu=name-of-the-dish2 http://myrestaurant.com/menu
Redirect 301 ?foodmenu=name-of-the-dish3 http://myrestaurant.com/menu
Redirect 301 ?foodmenu=name-of-the-dish4 http://myrestaurant.com/menu
Make all this in one line or function, something similar to:
Redirect 301 ?foodmenu* http://myrestaurant.com/menu
NOTE: this requests are multilanguage, so I will need more than one rule / redirect:
Redirect 301 ?foodmenu=name-of-the-dish3 http://myrestaurant.com/menu
Redirect 301 /ca?foodmenu=name-of-the-dish3 http://myrestaurant.com/ca/menu
Redirect 301 /es?foodmenu=name-of-the-dish3 http://myrestaurant.com/es/menu
You can not match against query strings in redirect directive, try :
RewriteEngine on
RewriteCond %{THE_REQUEST} \?foodmenu=([^\s]+) [NC]
RewriteRule ^ %{REQUEST_URI}menu? [L,R]
I found a website linking to my site with www.example.com/home.html which doesn't exist. I tried to set up a redirect:
Redirect 301 /home.html //www.example.com
But it redirects to www.example.com/www.mysite.com
Can I use the Redirect, or do I have to do a rewrite?
please use rewrite rule:
first:
Options +FollowSymLinks
RewriteEngine On
and then
RewriteRule ^home.html$ http://www.example.com/ [r=301,nc,L]
Redirect 301 /home.html //www.example.com
In this case, the target URL (starting with a slash) is seen to be root-relative to the current scheme/host. Providing you have a DirectoryIndex setup appropriately, you can just redirect to /.
For example:
Redirect 301 /home.html /
Would be so very grateful if someone can help me with this... I have been using a .htaccess 301 redirect file on my personal side business website for a while now however after a certain point in the file, the redirects simply do not work (returning a 200 in Rex Swain's http header tool).
I've looked through the file with a fine toothcomb and where the redirects stop working there are no issues at all (e.g. the urs are exactly as they should be). Really do not know why they would stop redirecting after a certain point?
Does anyone have any thoughts / recommendations? For anyone that would be willing to help I could send the file across.
Look forward to hearing from you,
Motley
Here's the code, the last line is the redirect that doesn't work. All before this work completely fine. There are other redirects after the last one (ive just not shown them), which also do not redirect. There is also a blank line at the end of the file.
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{http_host} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain/$1 [L,R=301]
Options +FollowSymLinks
RewriteEngine on
# index.html to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
Redirect examples
Redirect 301 /spas/alexander-house/overnight-packages http://www.domain/spas/alexander-house/spa-breaks
Redirect 301 /spas/alexander-house/day-packages http://www.domain/spas/alexander-house/spa-days
Redirect 301 /spas/alexander-house/weekend-packages http://www.domain/spas/alexander-house/spa-weekends
Redirect 301 /spas/armathwaite-hall/overnight-packages http://www.domain/spas/armathwaite-hall/spa-breaks
Redirect 301 /spas/armathwaite-hall/day-packages.html http://www.domain/spas/armathwaite-hall/spa-days
Redirect 301 /spas/armathwaite-hall/weekend-packages http://www.domain/spas/armathwaite-hall/spa-weekends
Redirect 301 /spas/billesley-manor/overnight-packages http://www.domain/spas/billesley-manor/spa-breaks
Redirect 301 /spas/billesley-manor/day-packages http://www.domain/spas/billesley-manor/spa-days
Redirect 301 /spas/billesley-manor/weekend-packages http://www.domain/spas/billesley-manor/spa-weekends
Redirect 301 /spas/bishopstrow-house/overnight-packages http://www.domain/spas/bishopstrow-house/spa-breaks
Redirect 301 /spas/bishopstrow-house/day-packages http://www.domain/spas/bishopstrow-house/spa-days
Redirect 301 /spas/bishopstrow-house/weekend-packages http://www.domain/spas/bishopstrow-house/spa-weekends
Redirect 301 /spas/bovey-castle/overnight-packages http://www.domain/spas/bovey-castle/spa-breaks
Redirect 301 /spas/bovey-castle/day-packages http://www.domain/spas/bovey-castle/spa-days
Redirect 301 /spas/bovey-castle/weekend-packages http://www.domain/spas/bovey-castle/spa-weekends
Redirect 301 /spas/castlemartyr/overnight-packages http://www.domain/spas/castlemartyr/spa-breaks
Redirect 301 /spas/castlemartyr/day-packages http://www.domain/spas/castlemartyr/spa-days
Redirect 301 /spas/castlemartyr/weekend-packages http://www.domain/spas/castlemartyr/spa-weekends
Redirect 301 /spas/celtic-manor/overnight-packages http://www.domain/spas/celtic-manor/spa-breaks
Redirect 301 /spas/celtic-manor/day-packages http://www.domain/spas/celtic-manor/spa-days
Redirect 301 /spas/celtic-manor/weekend-packages http://www.domain/spas/celtic-manor/spa-weekends
Redirect 301 /spas/chewton-glen/overnight-packages http://www.domain/spas/chewton-glen/spa-breaks
Did you try moving the Redirect to a different line in the .htaccess file? If the redirects following the new line location of Redirect 301 /spas/chewton-glen/overnight-packages http://www.domain/spas/chewton-glen/spa-breaks aren't working now then you know it is this Redirect alone that is causing the problem. Did you try removing this one redirect and see if the preceding redirects now work? I bet it has something to do with the chewton-glen directory?
I need to redirect all the old URLs on my site to new URLs, but am having issues. A given URL and its subfolders need redirecting to the same page.
For example, this is the first one:
redirect 301 /panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html
This works ok. However there are these size sub-pages which need to redirect to the same location:
redirect 301 /panache/sports-bra/30DD http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30E http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30F http://www.newdomain.co.uk/sports-bra.html
And these don't work, I end up at a location like the following:
http://www.newdomain.co.uk/sports-bra.html30DD
See the way the last part of the path is appended to the url? I'm guessing it's because the second redirect is conflicting with the initial 301 redirect?
I have also tried using this rewrite rule but have had no luck. The site is Magento so I don't know if this has some effect? mod_rewrite is enabled on the server.
RewriteRule ^panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html [R=301]
Any help mucha ppreciated.
Try this.
RewriteEngine on
RewriteRule ^(panache/sports-bra/.*)$ /sports-bra.html [L,R=301,NC]