Forum Moderators: phranque
[mysite.com...] (old)
to:
[mysite.com...] (current)
In other words, the character immediately following index.php went from "?" to "/". This is wrecking havoc for me with Google, as it still has thousands of pages indexed using the old URL structure that it doesn't want to give up. So basically I'd like to do a 301 Moved redirect in my .htaccess code so "index.php?" is effectively redirected to "index.php/" for all pages within /dir/. From what I gathered reading around here, this is what I have so far:
[pre]RedirectMatch 301 (index\.php\?)?$ index\.php/[pre]
I think I'm missing something with the second "index.php" above. Thanks for the help.
Thanks,
The question you ask, or a close variation of it, has been asked at least 5 times in the last 10 days. Please check the recent threads here in the forum, and the tutorials linked from the sticky thread at the top of the forum for more examples.
I would use a RewriteRule for this, because you will need a RewriteCond to deal with the QUERY_STRING part - as that is data appended to the URL. That way you can redirect old URLs to the exact new URLs rather than fold all the old URLs into just the folder.
You'll minimally need a Rewrite (I assume you already have that bit sewn up), but you should also consider a redirect for domain canonicalisation, as well as the redirecting of requests for the old URL over to the new URL that you asked about.
Be aware that RewriteRule can be coded to make rewrites or redirects. It's like a Swiss Army Knife; multipurpose.
This thread has all the steps and some extra ones, but for a URL with two parameters: [webmasterworld.com...]
RewriteEngine on
RewriteRule index.php?/([^/\.]+)\.html/?$ index.php/$1.html [L]
Can you tell me if I'm missing something here? Basically I need to redirect index.php?anything.html to index.php/anything.html as a 301. Not sure where I'd place the 301 redirect in the above though.
Thanks,
RewriteEngine on
#
RewriteCond %{QUERY_STRING} ^(.+\.html)$
RewriteRule ^index\.php$ http://www.example.com/index.php/%1 [R=301,L]
Jim
RewriteCond %{QUERY_STRING} ^(.+\.html)$
RewriteRule ^index\.php$ http://www.example.com/dir/index.php/%1? [R=301,L]
Can you let me know if that's in fact correct? A quick test seems to suggest it is, but you never know with mod_rewrite I've learned.