URL wont work: Problems with same folder name and file name

New to mod_rewrite? This is a good place to start.

Postby richardk » Tue Jul 29, 2008 12:33 pm

"." in a regular expression matched any character (for example the common usage ".*"). If you want it to only match "." use "\.".
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Re: URL wont work: Problems with same folder name and file name

Postby badlydrawnrob » Fri Jun 04, 2010 2:07 pm

So, it's been ages since I have needed to plunge the depths of .htaccess, but I am in need of advice again now.

After lots of messing about the only combination of rules I can get to work properly are as follows:

[code]
# Redirect 404 Error
ErrorDocument 404 /404.html

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://evokeartdesign.com/ [R=301,L]

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

#Add a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.+)$ /$1/ [L,R=301]

# Remove file extensions

RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+)/$ /$1.html [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.html$ /$1 [R=301,L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+)/$ /$1.php [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.php$ /$1 [R=301,L]
[/code]

However, I now have two issues that need resolving:

1. I need to allow a specific IP address to view all of the original file extensions online. This is due to CMS requirements which need to interact with original files, not truncated ones. I have been told this needs to go somewhere in the code (IP address in replacement of #):

[code]RewriteCond %{REMOTE_ADDR} ^###\.###\.###\.###[/code]

This would exclude this IP from the rules, i.e. allowing it to view them as normal. I'm not sure how to structure the code so that this will work, or if there is a catch-all statement which will do this for all the above.

2. The .htaccess code above as it is structured doesn't seem to allow for the 404 error to come into play. For instance if I type http://evokeartdesign.com/pagenotfound.html the only thing that happens is a trailing slash is added ... have you any ideas why the 404 error would not work in this instance?

Thanks in advance!
badlydrawnrob
 
Posts: 7
Joined: Wed Jul 23, 2008 8:45 am

Previous

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 11 guests

cron