Msg#: 4511714 posted 9:06 pm on Oct 24, 2012 (gmt 0)
#1 When you say
do you mean your domain (example.com) or do you mean a subdirectory? A RewriteRule only sees the path: the part after http://www.example.com and before the query, if any. In htaccess, leave off the leading slash in the pattern. Include it in the target when you are rewriting alone. (Your Redirect target is correctly formed, so don't change it.)
#2 a rule that explicitly says index.cfm$
will only pick up requests that either asked for this form in the first place (baaad!) or that have already been rewritten by mod_dir. This normally executes after mod_rewrite, but in htaccess you can't make assumptions so rules should allow for both forms:
RewriteRule ^directory(/(index\.cfm)?)?$ et cetera.
The double-nested ? elements are to avoid a double redirect if you get a request missing the final directory slash. Remember to escape all literal periods in the pattern. Sometimes it doesn't make much difference; sometimes it's crucial.
Are you really making 325+ separate rules, or is that just your example?
Do you really need the new URL to end ".htm"? I would aim for extensionless URLs on the new site.
Additionally, if there are a large number of these redirects to perform, you would be better off not having a huge list of redirects in the htaccess file.
Instead you should internally rewrite (that's internally rewrite using a single rule, not externally redirect) all of these requests to a special PHP script that looks up the new URL in an array and uses the PHP HEADER directive to send a 301 redirect to the new URL.
You can use a language other than PHP if you want, this was just an example.
This internal rewrite must unusually appear near the beginning of the htaccess file (after the rules that block access, and before rules that redirect). You MUST also ensure that these requests cannot be redirected by the non-www/www rule in the htaccess file (add a RewriteCond exclusion to that rule) otherwise non-www requests for the old URLs will expose the special-script internal path back out on to the web as a new URL and create a double redirect chain for those requests.
Msg#: 4511714 posted 2:27 pm on Oct 25, 2012 (gmt 0)
@lucy24, yes, I actually meant a subdirectory It's not 325 redirects, I'll only need 18 of them :)
@g1smd, genius. It's working now! Thank you.
I cannot say I understood the last paragraph but it does sound like a disaster and I'll have to read something about .htaccess. However, after uploading the .htaccess I tried both http://www.example.com/site/index.cfm?pageid=325 and http://example.com/site/index.cfm?pageid=325 They redirect to http://www.example.com/new-url.htm which I suspect is a good thing :)
Msg#: 4511714 posted 4:16 pm on Oct 25, 2012 (gmt 0)
Yes. You must test with both www and non-www requests. Use the Live HTTP Headers extension for Firefox to look in detail at the reponses. You need to make sure there are no chains. Try also adding another junk parameter on the end of the request and make sure that request is also correctly redirected.
With only 18 redirects, doing this in htaccess is fine.
You may want to try out the "rewrite to a script" version so that you are familiar with it for when you need it on a really big site. I'm using it to redirect 80 000 duplicate content and old-style URLs to 1200 new extensionless URLs on one site.
The stuff about correct "404" responses was for when you use a PHP (or other) script not a pure htaccess solution.