Forum Moderators: phranque
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?
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
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