Forum Moderators: bakedjake
Also, I want the rule to take effect whether the URI is "short" i.e. foo.com/page.cfm?var=23 or "long" foo.com/1/2/3/4/5/page.cfm?var=23 or foo.com/1/2/3/4/5/6/page.cfm without having to specify all the levels of directory structure within the rule.
I have tried a couple of rules but just get server errors.
Welcome to WebmasterWorld [webmasterworld.com]!
Post what you've got, and let's see what's wrong with it... We generally try to help you learn, not do it for you.
Ref: Introduction to mod_rewrite [webmasterworld.com]
(See the cited regular expressions tutorial, and check out "anchors".)
Jim
>> either a question mark and/or (...) the request is sent onto the script redirect.php
If redirect.php also accepts parameters and these are identified using a questionmark then you'll have a loop which is a thing to avoid.
Anyway, search for 301 redirect using the site search on top if you are starting from scratch, it's one of the subjects in here that has a lot of threads. You problem has been solved before, i'm sure.
/claus
No, redirect.php will in itself pick up the REQUEST_URI and then do stuff.
We are changing a site that uses .cfm URIs possibly also with query strings and we want to send all old .cfm and/or URIs with query strings to their new /some/other/nice/uri.html counterpart - but there is no direct relationshuip between old.cfm?url=foo and new/nice.html urls so redirect.php will do a DB lookup based on the REQUEST_URI - which if it comntains .cfm and/or a query string we know it must be an old URI or a 404.
I am still working on this and will post a solution here but if anyone comes up with anything before then, I much appreciate the input.
Thanks.
Naturally, that old trick works but the problem is that the web server throws a 404 status code and we want the redirection to be seamless so that after redirection to redirect.php, the user is displayed the URI they typed in, the new URI, there is a 10 second delay before redirection to the new URI and the redirect.php sets a 301 status code to the user's browser so search engine listings for old pages built over the years are not lost with a 404 but the search engines *should* update their listing with the 301/RedirectPermanent URI.
RewriteEngine on
RewriteCond %{REQUEST_URI}(.*)\.cfm$ ^/(except¦cgi-bin¦css¦images¦logs)/?.*$
RewriteRule ^(.+) - [L]
RewriteRule ^%{REQUEST_URI}(.*)\.cfm$ redirect.php [T=application/x-httpd-php,L]
RewriteRule ^%{REQUEST_URI}(.*)\.?$ redirect.php [T=application/x-httpd-php,L]
To recap we want:
* If the URI requested contains a question mark anywhere in the URI
AND/OR
* If the URI requested contains the filename extension .cfm anywhere in the URI
...then the request is sent onto the script redirect.php which does everything else.
...all other requested URIs including 404s are left alone.
I also want the rule to take effect whether the URI is "short" i.e. foo.com/page.cfm?var=23 or "long" foo.com/1/2/3/4/5/page.cfm?var=23 or foo.com/1/2/3/4/5/6/page.cfm without having to specify all the levels of directory structure within the rule.
Thanks.
Redirect to /redirect.php if .cfm extension or non-blank query string:
RewriteEngine on
RewriteCond %{REQUEST_URI} \.cfm$ [OR]
RewriteCond %{QUERY_STRING} .
RewriteRule !^redirect\.php /redirect.php [T=application/x-httpd-php,L]
RewriteRule !^/redirect\.php /redirect.php [T=application/x-httpd-php,L]