Forum Moderators: phranque
I am trying to redirect some shtml pages from an old message board to a new message board.
Here is the current RedirectMatch I am using:
RedirectMatch 301 /oldforum/(.*) http://new.example.com/forum/showthread.php?t=$1
Now this works. But lets say you are trying to goto an old thread (12345.shtml) for example, it will send you to:
http://new.example.com/forum/showthread.php?t=12345.shtml
The page loads, but I would like to remove the trailing .shtml from the redirect.
I was reading on this forum, and it seems that using something like a "RewriteRule" with a [0-9] accepting rule would be more efficient than using the .* method. But im still not sure how to pull that off correctly going from shtml files to the showthread.php
Thanks for your advice.
[edited by: jdMorgan at 2:48 pm (utc) on Nov. 25, 2009]
[edit reason] example.com [/edit]
Improving your pattern to specify ".shtml" requests and/but leave that file extension out of the back-reference will very likely fix this problem:
RedirectMatch 301 ^/oldforum/([0-9]+)\.shtml$ http://new.example.com/forum/showthread.php?t=$1
Jim
I understand what your saying and it provides useful insight.
However, when I tried changing my RedirectMatch to your format, the redirect no longer works. I checked apache access and error log and do not see any errors.
I'm not sure if this matters, but let me provide you with some more directory structure of the old folders:
RedirectMatch 301 ^/oldforum/([0-9]+)\.shtml$ [new.example.com...]
For the above directive, the ^/oldforum/ is located at:
/var/www/html/forum/messages/12345/*.shtml
there are also other folders such as:
/var/www/html/forum/messages/12346/*.shtml
I'm not sure how important that information is, so feel free to ignore it :)
THanks.
However, if "/forum/messages" does not appear in the URLs you are typing, then that implies that these URLs are being rewritten from the URL "/oldforum/nnn.shtml" to the filepath "/forum/messages/nnn.shtml" by other config code on the server, in which case that's a rather important factor that must be taken into account here...
Jim
Where I gave the file path, that is the actual path. But where I mention oldforum, it is because I wanted to make it more clear about which was the old part. When I place it in the htaccess, I of course change it to the correct name.
For "So it sounds like the string "/oldforum/" in the code posted above needs to be changed to "/forum/messages/"
I actually am placing the .htaccess file in: /var/www/html/forum/messages/, so I change the string "/oldforum/" in the code to say "/12345/".
For your second point, /forum/messages is appearing in the URL I am typing, there is no rewriting happening. /forum/messages/12345/nnn.shtml would be the url someone would type.
I hope this clears things up. I apologize for any confusion.
I took out the ^ from the beginning of the path, and it started working correctly.
I looked at the one I had that worked, but was leaving the shtml on, and noticed that it did not have the ^ symbol before the file path.
RedirectMatch 301 /oldforum/([0-9]+)\.shtml$ [new.example.com...]
Is what ended up working.
I learned that the ^ is actually an important difference, because if you put the ^, you need to give the full folder path based from the root of the web-site. But if you leave it out, you only need to provide the path from where the .htaccess file is located.
Is there an advantage to doing it one way vs another? I figured it might be more efficient to have the .htaccess file in the /forum/messages/ folder, so apache doesn't have to look at the rule with every hit to the site.
Be as specific as possible to avoid unexpected results -- now or later. In server configuration, neatness and completeness count!
Jim