Htaccess Rewrite

Soldato
Joined
6 Jan 2005
Posts
3,633
Location
Cambridge
So, this is my current .htaccess:

Code:
Options +FollowSymLinks
RewriteEngine On 
RewriteRule about/ about.php
RewriteRule about about.php
RewriteRule contact/ contact.php
RewriteRule contact contact.php
RewriteRule ^([a-zA-Z]+)$ index.php?album=$1
RewriteRule ^([a-zA-Z]+)/$ index.php?album=$1

Which works fine at the moment, but when I want to go to a folder that actually exists, it sends the page to index.php?album=<foldername>, instead of the actual folder.

So, how can I make it so when I go to website.com/blog/, it goes to website.com/blog/ instead of website.com/index.php?album=blog

I tried
Code:
RewriteRule blog/ blog/
but that doesn't work.

Google doesn't seem to be helping a great deal.

Any help would be much appreciated.

edit: Solved :)

For anyone interested, this fixes it.
Code:
Options +FollowSymLinks
RewriteEngine On 
RewriteRule about/ about.php
RewriteRule about about.php
RewriteRule contact/ contact.php
RewriteRule contact contact.php
RewriteCond %{REQUEST_URI} !^/blog/?$
RewriteRule ^([a-zA-Z]+)$ index.php?album=$1
RewriteCond %{REQUEST_URI} !^/blog/?$
RewriteRule ^([a-zA-Z]+)/$ index.php?album=$1

Code:
RewriteCond %{REQUEST_URI} !^/blog/?$
Before the RewriteRule makes it ignore the folder /blog/ :)
 
Last edited:
Perhaps a better solution would be to use the -f and -d flags to check for existing files and directories, as follows:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
 
Back
Top Bottom