Welcome to WebmasterWorld Guest from 54.234.114.182

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)

Junior Member

10+ Year Member

joined:Sept 16, 2005
posts:76
votes: 0


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)

Full Member

10+ Year Member

joined:Dec 20, 2004
posts:330
votes: 0


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)

Junior Member

10+ Year Member

joined:Sept 16, 2005
posts: 76
votes: 0


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

Full Member

10+ Year Member

joined:Dec 20, 2004
posts:330
votes: 0


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)

Junior Member

10+ Year Member

joined:Sept 16, 2005
posts:76
votes: 0


Wow - brilliant - that worked a treat.

Thanks very much for your time and help.

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

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members