views:

51

answers:

0

So I've been trying to shorten my urls. The images I want to display are located at http://domain.com/images/pic.jpg

I would ideally like to be able to navigate to them by going to http://domain.com/pic.

I have got that bit working, with a few issues (commented on below). But now I can't navigate to http://domain.com/index.php because it's attempting to open http://domain.com/images/index.php

Would really appreciate any help on this, I'm still really struggling with mod_rewrite and everything below is just what I've been copying from various discussions online.

# Remove www.
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

# Remove /images/ from the URL. Turns http://domain.com/images/pic.jpg into http://domain.com/pic.jpg
RewriteCond $1 !^images/
RewriteRule (.*) /images/$1 [L]

# Remove trailing slashes if added. http://domain.com/pic.jpg/ silently redirects to http://domain.com/images/pic.jpg
# -- How can I get this to have it redirect to http://domain.com/pic.jpg ? Why is it showing the subdirectory?
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=permanent,QSA]

# All these remove the relevant file extensions. http://domain.com/pic.jpg becomes http://domain.com/pic
# -- This is exactly the result I want, but is there a more efficient way to write this??
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.jpg -f
RewriteRule ^(.+)$ $1.jpg [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.JPG -f
RewriteRule ^(.+)$ $1.JPG [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.gif -f
RewriteRule ^(.+)$ $1.gif [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.GIF -f
RewriteRule ^(.+)$ $1.GIF [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.png -f
RewriteRule ^(.+)$ $1.png [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.PNG -f
RewriteRule ^(.+)$ $1.PNG [L,QSA]