homepage Welcome to WebmasterWorld Guest from 54.211.34.105
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
index.php to index.html and remove query string
? still appears
leeds1

5+ Year Member



 
Msg#: 3867851 posted 9:44 am on Mar 11, 2009 (gmt 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.

 

Caterham

10+ Year Member



 
Msg#: 3867851 posted 9:47 am on Mar 11, 2009 (gmt 0)

You have to move to mod_rewrite (unfortunately) since mod_alias does not provide this feature.

leeds1

5+ Year Member



 
Msg#: 3867851 posted 11:54 am on Mar 11, 2009 (gmt 0)

Thanks - do you know the mod_rewrite code for such a situation?

Caterham

10+ Year Member



 
Msg#: 3867851 posted 12:09 pm on Mar 11, 2009 (gmt 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]

leeds1

5+ Year Member



 
Msg#: 3867851 posted 12:16 pm on Mar 11, 2009 (gmt 0)

Wow - brilliant - that worked a treat.

Thanks very much for your time and help.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3867851 posted 7:27 pm on Mar 11, 2009 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved