Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite help for simple issue!

         

stuckinbed

8:13 pm on Jul 20, 2006 (gmt 0)

10+ Year Member



My website is www.mywebsite.com

I want anything that is not a script or a file (e.g. www.mywebsite.com/example) to go to one master script.

I did this with..


RewriteEngine On
RewriteRule (\.) script.php

But when you go to www.mywebsite.com that is also being redirected. I don't want the default page that pulls up (www.mywebsite.com/index.php) to be redirected just because somebody types in www.mywebsite.com

Any help would be GREATLY appreciated.

jdMorgan

2:42 am on Jul 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The easiest fix is to simply exclude your index file from the rule:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} !^/script\.php
RewriteRule \. script.php [L]

Note: The second RewriteCond will be required if this code is placed in .htaccess, in order to prevent a rewrite loop. This is because the URL-path "script.php" matches your "\." pattern. The parentheses on your pattern are not required, since you are not back-referencing the pattern, and the [L] flag should be used unless you need the output of this rule (script.php) to be rewritten by subsequent rules in this config file.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim