Forum Moderators: phranque

Message Too Old, No Replies

.htaccess file not working as it should

         

AdDoctor

12:58 pm on Aug 5, 2014 (gmt 0)

10+ Year Member



Hi Everyone,

I have been a member for quite some time and this is my first post in a while.

I am trying to get my .htaccess file to issue redirects for thousands of URLs and whatever I am doing is not working.

Below is the code in my .htaccess file

# Permanent move from website1.com to website2.com
RewriteEngine On

RewriteRule ^/tigers/(.+) http://website2.com/bears/$1 [R=301,L]


What I was hoping this would do was redirect website1.com/tigers/xxxx to website2.com/bears/xxxx where xxxx can be any of thousands of different names. However what is happening is that I am being redirected from website1.com/tigers/xxxx to website2.comtigers/xxxx where "tigers" is not being replaced by "bears" and a "/" is missing in front of the url.

Any help would be appreciated

[edited by: phranque at 1:49 pm (utc) on Aug 5, 2014]
[edit reason] unlinked URL [/edit]

omoutop

1:29 pm on Aug 5, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule ^tigers/(.+)$ http://website2.com/bears/$1 [R=301,L] 


something like this perhaps?

penders

1:48 pm on Aug 5, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



omoutop's suggestion is sound, however, I can't see how your current RewriteRule is redirecting anything. It shouldn't match anything and consequently fail silently... because of the slash prefix on the RewriteRule pattern (the directory prefix is removed in per-directory .htaccess files) before the pattern is matched.

Original RewriteRule:
RewriteRule ^/tigers/(.+) http://website2.com/bears/$1 [R=301,L]

website1.com/tigers/xxxx to website2.comtigers/xxxx


?

lucy24

6:41 pm on Aug 5, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule ^/

This will always fail in htaccess (or <Directory> sections in config). Leave off the initial slash.

Incidentally, you can say example.org, example.net, example.xyz, example.abc and so on if you need to distinguish among different names. Any tld, including ones that don't exist. No subdomains, though.