Redirect 301 of subdirectory - .htaccess

There was a link example.com/shop/product-1
now link is example.com/newshop/product-1
I try to wtite htaccess rule to redirect from /shop/ to /newshop/
RewriteRule ^(.*)shop(.*)$ $1newshop$2 [QSA,L,R=301,NC]
Doesn't work. Where is mistake?

You can use the following redirect
Redirect 301 /shop/ /newshop/
This will redirect /shop/.* to /newshop/.*

Related

How to Redirect every link beginning with the same word in .htaccess?

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]

htaccess redirect 301 pro.php to index.php for many directories

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

301 Redirect to homepage returning a 404

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 /

.htaccess - redirects after a certain point in the file not working

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?

301 redirect from htaccess

I'm trying to create permanent redirects for outdated URL's on my site.
For example I have: www.mydomain.com/?v=tv and want it have a permanent 301 redirect to www.mydomain.com/tv.php
I tried this code in my htaccess file but it did not work:
Redirect /?v=tv http://mydomain.com/tv.php
Any Help?
RewriteRule ^tv.php$ http://guessthelogo.com/?v=tv [R=301,L]
I think your missing "301" after "Redirect":
Redirect 301 /?v=tv http://guessthelogo.com/tv.php

Resources