Forum Moderators: phranque

Message Too Old, No Replies

rewrite problem after CMS change

Changed to different CMS and need to redirect based on parameters

         

dplunkie

11:23 pm on Feb 22, 2008 (gmt 0)

10+ Year Member



We've changed from one CMS to another on our company Intranet (Joomla to ModX) and there are three specific URLs that I'd like to have automatically redirect.

One of the old addresses was:
[test.com...]
and the new page is at
[test.com...]

I'm using mod_rewrite on Apache 2, and I've included a line in it:
Redirect 301 /index.php\?option=com_wrapper&view=wrapper&Itemid=54 /email-list.htm
It just resolves to the main page of the site...
There is another rule that might be causing problems, but I need it for friendly URLs to work:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Unfortunately, the new CMS also uses the index.php format, but none of the same parameters are passed. Can I just parse those parameters strings and point to the new page for the three I really need? Why do I need these ones? They are marked as favourites and on the desktop of about 800+ PCs...and we don't have the resources to change all of them right away...

gergoe

11:39 am on Feb 23, 2008 (gmt 0)

10+ Year Member



I'm not sure Redirect takes the query string, but even if it would do so, you don't need to escape characters like the question-mark, that's only needed when working with regular expressions (and Redirect does not do that).

Why not make it with mod_rewrite?

RewriteCond %{QUERY_STRING} option=com_wrapper&view=wrapper&Itemid=54 [NC] 
RewriteRule ^index\.php$ http://www.example.com/email-list.html [R=301,L]

jdMorgan

9:09 pm on Feb 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Redirect and RedirectMatch directives cannot see the query string, so you should use mod_rewrite as suggested above.

Jim

dplunkie

2:31 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



It seems to conflict with the other RewriteRule. I have a local test site with a domain of test.wip (Apache on Windows) and it gives:
[test.wip...]

for the following rules:
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

RewriteCond %{QUERY_STRING} option=com_wrapper&view=wrapper&Itemid=54 [NC]
RewriteRule ^index\.php$ [test.wip...] [R=301,L]

I've moved the query string condition and rule both before and after the request filename. Can I put the Query string one first and then prevent other RewriteRules from happening?

jdMorgan

9:17 pm on Feb 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, I'd say try it and see -- Certainly much faster than waiting around here... :)

As a general rule, all external redirects should go first, in order from most-specific patterns and conditions to least-specific, followed by all internal rewrite, again from most- to least- specific.

Be aware that your currently-first rule will rewrite any request to index.php if the request does not resolve to an existing file or directory. The currently-second rule does an external redirect to test.wip/blog.htm.

So whether this code loops or not hinges on which of the target URLs actually exists as a file, and on whether the redirect is to a domain that is also handled by this same .htaccess code. Not knowing which or whether those possibilities exist, I can't tell why the code is looping.

You can always explicitly prevent a rule from being re-invoked (and looping) by excluding the target URL in a RewriteCond. For example, if index.php in the first rule does not actually exist, then you'd need to add


RewriteCond %{THE_REQUEST} !^/index\.php$

to stop that rule from looping. For the sake of efficiency, you'd want to make that the first RewriteCond, so that the slow and inefficient "exists" checks are skipped if the request is for index.php.

Jim

dplunkie

9:35 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



Thanks for your help and knowledge.
By playing around I was able make it go to index.php?q=xx, and though it doesn't have a "friendly" url it works because it's not processing the other rule again.
I'll do some more playing around when I get some spare time (currently scheduled for August!). I'll try to make it go to to the other by adding the request condition.