More Mod_Rewrite --- I'm still learning, but please help.

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

More Mod_Rewrite --- I'm still learning, but please help.

Post by tecktalkcm0391 »

I have this in the .htaccess on the base of my site (site.com)

Code: Select all

RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP 
RewriteRule (.*)\.php$ $1 [R=301]
Thas gets rid of the .php on any site page, but how can I turn that off for http://site.com/folder?

Also, I have this:

Code: Select all

RewriteRule ^us/([A-Za-z]+)/([A-Za-z0-9]+)/$ us.php?state=$1&page=$2 [NC]
When ever I go to US/Florida/ its gives me a 404 error when it should show up a default page.
When ever I go to US/Florida/Page1 it works.

But when ever I use the US/State/Page... the page doesn't really work because of its links to files in other folders (example. stylesheet in site.com/css)

Why is that happening?
arkady
Forum Newbie
Posts: 23
Joined: Sun Sep 17, 2006 9:34 pm

Re: More Mod_Rewrite --- I'm still learning, but please help

Post by arkady »

tecktalkcm0391 wrote:I have this in the .htaccess on the base of my site (site.com)

Code: Select all

RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP 
RewriteRule (.*)\.php$ $1 [R=301]
Thas gets rid of the .php on any site page, but how can I turn that off for http://site.com/folder?

Also, I have this:
Try popping a .htaccess file in that subdirectory turning Rewrite Off.

Code: Select all

RewriteRule ^us/([A-Za-z]+)/([A-Za-z0-9]+)/$ us.php?state=$1&page=$2 [NC]
When ever I go to US/Florida/ its gives me a 404 error when it should show up a default page.
When ever I go to US/Florida/Page1 it works.

But when ever I use the US/State/Page... the page doesn't really work because of its links to files in other folders (example. stylesheet in site.com/css)

Why is that happening?
You're likely using relative paths to the images/files etc... so what you'd probably want to do is change the generated links (based on the header info) to be something like ../../mystylesheet.css where the page is US/Florida/blah.php etc.. Don't forget that as far as the page is concerned it is actually at that /US/Florida location, apache does all the necessary translation to make it work.
Post Reply