homepage Welcome to WebmasterWorld Guest from 54.227.34.0
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

    
mod_rewrite problem, how to exclude text from the rule
how to exclude some text from the mod rewrite rule
parorrey

5+ Year Member



 
Msg#: 4124 posted 11:33 am on Jul 20, 2005 (gmt 0)

hi,

i m using the following rule and i m sure it can be much better, i ve very lil experience with rewriting. so help.

i want my index.php file to open when typed www.domain.com/some-directory/
but i ve defined some rule to rewrite any page like this some-directory/some-page.php to this some-directory/services.php?name=(some-page)

RewriteRule some-directory/(.*)$ /services.php?name=$1

problem is above defined rule takes every request to the services.php page, i ve tried the following rule too
RewriteRule some-directory/[^(index)](.*)$ /services.php?name=$1
but i ve not been able exclude the index.php from being processed. can someone plz tell how to group the text correctly and exclude it.
thanks

 

jdMorgan

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



 
Msg#: 4124 posted 1:54 pm on Jul 20, 2005 (gmt 0)

parorrey,

Welcome to WebmasterWorld!

Just add a Rewrite Condition ahead of the rule to exclude /some-directory/index.php from being rewritten:

RewriteCond %{REQUEST_URI} !^/some-directory/index\.php$
RewriteRule ^some-directory/(.*)$ /services.php?name=$1 [L]

I assume that your code is in .htaccess. For use in httpd.conf, the above will need to be modified.

Jim

parorrey

5+ Year Member



 
Msg#: 4124 posted 5:55 am on Jul 21, 2005 (gmt 0)

thank u so much for the quick reply, code worked fine and yes i 'm using it in .htaccess file.

there was a lil problem though, code worked fine for index.php at the end of path but it did not work when there was only domain/some-dir/
i had to add some to check the '/', modified code was

RewriteCond %{REQUEST_URI}!^/some-dir/index\.php$
RewriteRule ^some-dir/[^/](.*)$ /services.php?name=$1 [L]

even though its working fien now but is there a better way to do it?

btw, thanks for welcoming. :)
-Ali

jdMorgan

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



 
Msg#: 4124 posted 2:52 pm on Jul 21, 2005 (gmt 0)

Modify the RewriteCond to make "index.php" optional:

RewriteCond %{REQUEST_URI} !^/some-directory/(index\.php)?$
RewriteRule ^some-directory/(.+)$ /services.php?name=$1 [L]

The RewriteCond will now match either "/index.php" or "/".

Jim

parorrey

5+ Year Member



 
Msg#: 4124 posted 4:12 am on Jul 22, 2005 (gmt 0)

thanks, worked like charm.
another question arises here, what if i 've to make another file in the directory to exempt the rule, for instance, contact.php and/or about.php other than index.php
-Ali

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