Welcome to WebmasterWorld Guest from 54.145.173.36

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

index.php to index.html and remove query string

? still appears

   
9:44 am on Mar 11, 2009 (gmt 0)

5+ Year Member



Hi

I used to have a index.php file under wordpress in my root directory which of course generates queries for "next pages" and the like, such as:

example.com/index.php?c=81&s=11 etc

I want to redirect all cases of index.php to index.html or rather just the example.com as I don't use index.php any longer.

I have the following code in my .htaccess file:


Redirect 301 /index.php http://www.example.com/?

Which does the trick except it leaves the "?" at the end. if I remove the "?" at the end the complete query string is shown, ie: example.com/?c=81&s=11

Any ideas? Thanks.

9:47 am on Mar 11, 2009 (gmt 0)

10+ Year Member



You have to move to mod_rewrite (unfortunately) since mod_alias does not provide this feature.
11:54 am on Mar 11, 2009 (gmt 0)

5+ Year Member



Thanks - do you know the mod_rewrite code for such a situation?
12:09 pm on Mar 11, 2009 (gmt 0)

10+ Year Member



If you're on Apache 2.+ you could use

RewriteEngine on
RewriteRule ^index\.(?:html¦php)$ /? [R=301,L,NS]

Edit: BTW: you'll have to replace the ¦ pipe with a solid one from your keyboard since this character is modified by the forum software.

[edited by: Caterham at 12:13 pm (utc) on Mar. 11, 2009]

12:16 pm on Mar 11, 2009 (gmt 0)

5+ Year Member



Wow - brilliant - that worked a treat.

Thanks very much for your time and help.

7:27 pm on Mar 11, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I would always also include the domain name in the redirect target URL so that both incoming non-www and www requests are fixed to the canonical form of your choosing.