Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite question

         

chrysb

4:07 pm on Aug 11, 2005 (gmt 0)



I am having some complications with RewriteEngine

Here is my .htaccess file:


RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^/]+)/$ index.php?section=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ index.php?section=$1&post=$2 [L]

Basically, I want:

www.myplainlife.com/rants/

to be /index.php?section=rants

and I want

www.myplainlife.com/rants/Name_of_article

to be /index.php?post=Name_of_article

The way it is now, either one works or the other (if I swap the order of the rules), not both together. Also if the second rule is working, the images no longer show up on my site. Any one have any knowledge?

ChadSEO

5:45 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



chrysb,

Welcome to WebmasterWorld!

I would imagine the images don't work because your rule is trying to redirect them, so you'll want to add another condition to ignore them. Also, I would guess that the second rule is not working because you need to duplicate your RewriteCond matches. And lastly, I'm not sure if "%{REQUEST_FILENAME} -d" is the most effecient way to test, but I don't have a better way. Someone else may have a suggestion.

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/images/ [NC]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^/]+)/$ index.php?section=$1 [L]
RewriteCond %{REQUEST_URI} }!^/images/ [NC]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^/]+)/([^/]+)$ index.php?section=$1&post=$2 [L]

Chad

jd01

8:44 pm on Aug 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, I think the directory flag is unnecessary, and may be causing the problem (especially, since we are serving information to a directory that does not exist)...

RewriteEngine on
RewriteRule images - [L]
RewriteRule ^([^/]+)/$ /index.php?section=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ /index.php?section=$1&post=$2 [L]

# if you really only want post= in the second rule, you would use this:
RewriteRule ^[^/]+/([^/]+)$ /index.php?post=$1 [L]

Other than that, the rules look fine. Please note, I did remove the base and inserted the preceding / on the right side of the rule.

Justin

Added: image rule