|301 redirection (with 2 directories)|
I need help with a 301 redirection. The URL contains 2 directories.
| 9:52 pm on Feb 19, 2014 (gmt 0)|
I am having trouble with a 301 redirection set up.
I need to redirect
I wrote this in the .htaccess :
Redirect 301 /directory1/directory2/
And when I submit the .htaccess file there is an error. The Page is not found and I am redirected to
http://myotherwebsite/en/adifferentdirectory/directory2 . This makes no sense because the redirected URL and the destination URL are mixed.
This code works when there is just one directory :
Redirect 301 /directory1/
| 11:45 pm on Feb 19, 2014 (gmt 0)|
|The Page is not found and I am redirected to http://example.com/en/adifferentdirectory/directory2 |
I think you mean this the other way around: first you are redirected, and then you end up on a different page.
Are you quoting the rules exactly as they appear in htaccess? I would expect complications when one side ends in a directory slash and the other doesn't.
Fine-tooth-comb your htaccess. It sounds as if there is an earlier rule naming /directory1/ alone, which executes before the request ever gets a chance to see the longer rule. Always put specific rules before general ones, so a rule involving
comes before anything naming
Important! Does your htaccess file currently have any RewriteRules at all? If so, you need to change all rules using mod_alias (Redirect or RedirectMatch by that name) to RewriteRules, because mod_rewrite always executes before mod_alias in htaccess.
Now do you see why the Forums rules insist on "example.com"? It can be example dot anything if you're discussing more than one domain.
| 3:12 pm on Feb 20, 2014 (gmt 0)|
Thank you for your answer.
To answer your questions :
I am quoting rules exactly as they appear in the htaccess.
As you recommended, I put the specific rules before general ones.
That works but not for all the URL. For example, I have now in my htaccess :
Redirect301 /directory1/directory-2A http://example.com/directory3
Redirect301 /directory1/directory-2B http://example.com/directory3
Redirect301 /directory1/directory-2C http://example.com/directory3
Redirect301 /directory1/directory-2D http://example.com/directory3
Redirect301 /directory1/ http://example.com/directory3
RedirectMatch 301 ^/directory1/directory2E.*$ http://example.com/directory3
Redirect 301 /directory1/directory-2F http://example.com/directory4
The URL with directory 2A and directory 2C works. The /directory1/ works too. The others redirections don't work.
I don't have any Rewrite Rules and I am using Redirect and RedirectMatch.
For the redirections that don't work, they bring me to a URL that is a mix of the directories of redirected URL and those of the destination URL.
That means that at the ends my URL is : http://example.com/directory4/directory2B.
I hope it is clearer.
Thank you for your help.
| 4:26 pm on Feb 20, 2014 (gmt 0)|
welcome to WebmasterWorld, eugenie_848!
have you cleared your browser cache before testing server directive edits?
you may be seeing some old cached redirects.
| 5:20 pm on Feb 20, 2014 (gmt 0)|
Thanks for the welcoming.
So, finally, the answer was :
1 - The general URL was before the specific URLs. Thanks Lucy21 for that tip.
2 - A cache problem. Thanks Phranque :)
| 11:15 pm on Feb 20, 2014 (gmt 0)|
|RedirectMatch 301 ^/directory1/directory2E.*$ http://example.com/directory3 |
directory3-what? When using RedirectMatch, you have to spell out the target using captures. Otherwise the target is taken as-is, with nothing reappended. If it's a real, physical directory, call it /directory3/ since that's its real name. Otherwise every redirect will be followed by a second redirect for the directory slash.
|For the redirections that don't work, they bring me to a URL that is a mix of the directories of redirected URL and those of the destination URL. |
That's why I suspected a rule-ordering problem. For example:
Redirect 301 /directory http://www.example.com/dir2
Redirect 301 /directory/innerdirectory http://www.example.com/dir3
because the rules execute in the order you list them.