Welcome to WebmasterWorld Guest from 54.144.243.34

Forum Moderators: Ocean10000 & incrediBILL & phranque

Preventing rewrite of a root request

but everything else gets rewritten

   
12:28 pm on Jan 31, 2009 (gmt 0)

10+ Year Member



Hi,

I have a site which is rewriting all urls to the main index.php file.

However, I DON'T want it to rewrite the main url - I want that to go to index.html (where we have a holding page).

The .htaccess rule for the rewrite is simple:
RewriteEngine on
RewriteCond $1 !^(index\.php¦images¦robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

But how do I stop it from rewriting the root www.example.com ?

Thanks in advance for any help :-)

3:29 pm on Jan 31, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Change (.*) in the rule to (.+)

Neither the start nor the end anchor are needed, since these are both 'greedy' patterns.

Jim

3:51 pm on Jan 31, 2009 (gmt 0)

10+ Year Member



Thanks so much, I never would have figured that one out, much appreciated.
6:17 pm on Jan 31, 2009 (gmt 0)

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



You rule also rewrites searchengine verification file URLs and a whole host of other stuff that you probably don't want to rewrite.
12:22 pm on Feb 1, 2009 (gmt 0)

10+ Year Member



That bad? I'm using CodeIgnitor, and that's the suggested rule they give in their User Guide. If there's a better option, please pass it on to me and I'll post it to their forums to share with others. Many thanks.
6:54 pm on Feb 1, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The point is simply that the RewriteCond may need to exclude other "common" URL-paths such as requests for /sitemap.xml, /w3c/p3p.xml, /labels.rdf, and search engine "webmaster tools" validation files such as /google<16 hexadecimal digits>.html, /y_key_<16 hexadecimal digits>.html, and /LiveSearchSiteAuth.xml, other files not handled by your script such as external CSS stylesheets and JavaScript files, .pdf and .xls, files, multimedia files, and /favicon.ico.

Unless excluded, *all* requests must be handled properly by the script.

I'm not familiar with CodeIgniter, but you'd also do well to test thoroughly to make sure that if it cannot find a requested resource, it returns a proper 404-Not Found header, and NOT a 200-OK (no matter what the page content it returns might be).

Jim

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month