Adil
Adil

Reputation: 3193

trying to get mod_rewrite to work

I have this problem where I switched CMS from the old one to the new one so I am trying to redirect urls properly.

Here are some example urls I wanted to convert:

#-1) http://www.mysite.com/?dispatch=search_data&features=hash_tag
#-2) http://www.mysite.com/index.php?dispatch=search_data&features=hash_tag

Basically both of them are identical except the first one doesn't have index.php in the url.

I got the following to code to partially work:

 RewriteCond %{QUERY_STRING} dispatch=(.*)
 RewriteRule ^$ http://www.mysite.com/? [L,R=301]

The above code works for #-1 (when there is no index.php) but when there is index.php it doesn't work.

Any help / guidance is much appreciated.

Thanks

____________UPDATE_______________

As per request, here is what the the target url should be: http://www.mysite.com/

Upvotes: 1

Views: 61

Answers (3)

Devin Ceartas
Devin Ceartas

Reputation: 4829

RewriteCond %{QUERY_STRING} dispatch=(.*)
RewriteRule ^(index.php)?$ http://www.mysite.com/? [L,R=301]

Upvotes: 1

tangentstorm
tangentstorm

Reputation: 7315

What do you mean it "works"?

You should probably post an example of what you want the new url to look like given the old url.

But in any case, part of your problem is that the RewriteRule line is specifically excluding index.php and any other page on your site.

What you wrote basically tranlates to this:

if the query string contains "dispatch=...":
    redirect requests FOR THE HOME PAGE ONLY (^$) to http://www.mysite.com/

Upvotes: 2

Scott M.
Scott M.

Reputation: 7347

have you tried changing the second part to include the "index.php" part?

RewriteRule ^$ http://www.mysite.com/index.php? [L,R=301]

Upvotes: 0

Related Questions