I want to make some redirect like this:
Redirect 301 /foo /foo/bar/index.html
Problem is, it creates a loop.
Intuitively I would expect this redirect would match /foo only and not /foo.*. But apparently things work differently. How can I fix this?
Use RedirectMatch instead of Redirect to be able to use regex for exact matching:
RedirectMatch 301 ^/foo/?$ /foo/bar/index.html
Make sure to use a new browser for testing this change.
Regex ^/foo/?$ will only match /foo or /foo/ but not /foo/anything.
This is an example .htaccess file of mine.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect 301 /CPP001/ https://mydomainaddress.com/cpp/student-app/
Redirect 301 /DSE001/ https://mydomainaddress.com/cpp/examples/virtual.html
Redirect 301 /DSE002/ https://mydomainaddress.com/cpp/examples/overload.html
Redirect 301 /ANK001/ https://mydomainaddress.com/cpp/com267/
Redirect 301 /ANK002/ https://mydomainaddress.com/c-programming/com267HW2/
Redirect 301 /WEB001/ https://mydomainaddress.com/web-programming/examples/index.html
Redirect 301 /NET001/ https://mydomainaddress.com/pdf/IPControl.pdf
ErrorDocument 404 https://mydomainaddress.com/
ErrorDocument 403 https://mydomainaddress.com/
Try to change your Redirect 301 /foo /foo/bar/index.html to Redirect 301 /foo http://yourdomain.com/foo/bar/index.html
If nothing inside index.html is causing another redirection, it's highly unlikely a loop will happen again.
Related
I need to redirect a lot of urls beginning with the same word to a new link.
Exemple:
Redirect 301 /old-text-1/ /new-link/
Redirect 301 /old-text-2/ /new-link/
Redirect 301 /old-text-3/ /new-link/
Redirect 301 /old-text-4/ /new-link/
Redirect 301 /old-text-5/ /new-link/
...
Can I redirect all this links in a better way?
I tried:
RewriteRule ^/old-text(.*)$ /new-link/ [R=301,L]
but it doesn't work.
You need to remove the trailing slash when using RewriteRule directive in .htaccess context.
RewriteRule ^old-text(.*)$ /new-link/ [R=301,L]
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 have this htaccess code which works fine to redirect all pro.php requests to index.php:
Redirect 301 /de/pro.php /de/index.php
Redirect 301 /en/pro.php /en/index.php
Redirect 301 /fr/pro.php /fr/index.php
BUT, is there an elegant possibility with just one line of code for manyfold directories /de /en /fr /.. ?
You can use RedirectMatch :
RedirectMatch ^/(.+)/((?!index).+)\.php$ /$1/index.php
I want to do a 301 redirect from old_page.php to new_page.php and keep all query strings if they exist.
so old_page.php would redirect to new_page.php
old_page.php?test=1 would redirect to new_page.php?test=1
Here is what I have below, but it's a 404 error.
RewriteEngine on
RewriteRule ^old_page.php(.*) new_page.php$1 [R=301,L]
This worked:
Redirect 301 /old_page.php /new_page.php
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?