Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We moved a part of our site from one sub folder to another. I want to put permanent redirects (301) into htaccess for the files in this folder (some have changed their filename as well, so I can't just setup one rule for the whole folder). Here's what I'm trying

RewriteRule ^search/tutorial-search.html$ db/tutorial.php [R=301]

This doesn't work though, I get a 404 response when now entering the old URL. I find this curious as I had a rule in place for ages that does work, which looks like this:

RewriteRule ^search/tutorial-search.html$ search/tutorial-search.php

I really don't see the big difference. I also tried the following (among others) but it doesn't work either

RewriteRule ^search/tutorial-search.html$ db/tutorial.php

What exactly is causing this to fail? Just to make sure I put all of these at the exact same line of the htaccess file. Is it because I'm rewriting to another folder? Thanks :)

share|improve this question
    
Where's the htaccess file located that has these directives? Is it all in the same htaccess, or have you split them up to different directories? –  Shane Madden Sep 25 '12 at 1:11
    
Actually posting your htaccess file so we can review it might be useful to figuring out that you're doing wrong, FYI. –  HopelessN00b Oct 7 '12 at 18:28
add comment

2 Answers

1) Please post your entire .htaccess

I'm guessing you don't have any of these wrapped in the proper directives.

If you want to redirect the traffic, you shouldn't be using a Rewrite rule as this just rewrites the URL. What you really want is Redirect rule

RedirectMatch permanent oldfolder/oldfile.html "http://www.mysite.com/newfolder/newfile.html" ...... (Insert each one that has changed named) RedirectMatch permanent /oldfolder/* "http://www.mysite.com/newfolder"

That will give you the 301 redirects you are looking for. Rewrite actually changes the URL that the browser is requesting. Redirect repoints the URL and tells the browser/search engine, "Hey, this stuff moved. It's over here now."

share|improve this answer
    
I can't post the complete .htaccess. It should be possible to analyse the matter without the complete htaccess anyways as a) it's a very early section 2) as I said, the ReWrite I had in place (the 2nd one) works if placed in exactly the same line in the htaccess. So it's not a problem like not having the Rewrite Engine on or whatever. Also, what you say about redirects and rewrites isn't exactly right. You can't even defined a "Redirect 301 ..." for dynamic pages (which I also have, this static one was just the first one I wanted to get working). A ReWrite with [R=301] IS a redirect 301. –  janb Sep 24 '12 at 22:26
add comment

You do not define the redirect as a 301. The "permanent" flag after the RedirectMatch does that in the Apache headers.

If you have a line that is working on that server in one place, and a line that is broken in another, you obviously have something missing.

Try copying the entire .htaccess file from the old location and removing all the rewrite rules but one. Then just edit that one.

And unfortunately without seeing what else you have or do not have in your .htaccess, it really is impossible to diagnose what is causing your issue.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.