Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod_rewrite Rule

Status
Not open for further replies.

sjkted

IS-IT--Management
Nov 27, 2002
28
US
Hello All,

I am trying to set up a mod_rewrite rule that will accomplish the following:

==>

I have come up with:

rewriterule ^(.*)\.php [L]

I have found that this does not work. When I change it to:


rewriterule ^(.*)\.html [L]

it does work for
==>

Unfortunately, I cannot use the second option because my entire site has hyperlinks written to the .PHP extension. Could someone suggest how to get it working with .PHP?

Thanks,

sjkted
 
Thanks for the quick response. In my example:

cmsindex.php?name=page_name

page_name is a variable

So, it could be

cmsindex.php?name=index
cmsindex.php?name=news
etc.

Thank you for the tip. I wasn't aware that this was how to break a loop condition. It seems that all I need at this point is how to change the RewriteCond line to accommodate the variable:

RewriteCond %{REQUEST_URI} ^/page_name.php

Thanks,

sjkted
 
I believe if you wildcard it (like you sort of had) then you will affect ALL phps. If you can stick this in a subdir, then you won't have this problem (by adding as an .htaccess or adding the subdir in the RewriteCond.

So generically, this is to take the php name and pass as a variable:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*)\.php$
RewriteRule ^(.*)$ [L]
 
Ok. I tried this with a few variants and I keep getting 500 server errors. It would be okay to move cmsindex.php to a test directory (which I also tested with the RewriteRule and RewriteCond) as it is the only PHP page that needs to be called on the entire site (with the exception of a few subdirectories).

sjkted
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top