Forum Moderators: phranque

Message Too Old, No Replies

apache variables in rewrite rules

apache & rewrite rules

         

phpist

10:25 am on Jul 22, 2007 (gmt 0)

10+ Year Member



hello everyone,

there are running 2 different php file as DirectoryIndex in same folder. but the problem is that there is a .htaccess file too in same folder. by the way, i'm using that .htaccess file for writing my rewrite rules.

----------------------------------------------------------
Apache Conf:
localhost , port:4321 , index.php
localhost , port:4322 , other.php
----------------------------------------------------------
Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI}!\.html$
RewriteRule .* - [L]

RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
----------------------------------------------------------

It's seem like perfect but it's not. My other DirectoryIndex never run because of that rewriterule. How can i use current DirectoryIndex value, not hardcoded index.php in the rule above?

Thank you for your time.

Umut

jdMorgan

3:12 pm on Jul 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you refer to the index page as "/", then the server should use the current value of "DirectoryIndex" to resolve "/" to the correct file. You can also code your two rules in a more compact single-rule form like this:

<IfModule mod_rewrite.c>
RewriteEngine on
#
RewriteCond $1 !\.. [OR]
RewriteCond $1 \.html$
RewriteRule (.*) / [L]
</IfModule>

Here, using DeMorgan's Theorem, we've changed the logic from
IF ( a AND (NOT b) ) THEN skip, ELSE rewrite.
to
If ( (NOT a) OR b ) THEN rewrite.

and we're also rewriting to "/" instead of rewriting to a specific file. Other changes were made to get rid of unnecessary regex tokens; The code should be entirely equivalent to what you had, but one-half the size.

Jim

phranque

12:06 am on Jul 23, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, phpist!