Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using RewriteCond %{REQUEST_FILENAME} !-f in apache rewrites

Status
Not open for further replies.

tewari68

Programmer
Jan 25, 2005
87
US
Hi,
I have to write a rewrite rule whereby if a url does not have a trailing slash I need to append the trailing slash.
For ex. should redirect to
I have this rewrite rule but this does not work

<code>
RewriteCond %{REQUEST_URI} /a/b
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [L,R=301]

</code>

if I give the url it works I get the correct page

however
if I give the url
In the rewrite logs I see
<code>
RewriteCond: input='/a/b/c/index.shtml' pattern='/a/b' => matched

RewriteCond: input='/a/b/c/index.shtml' pattern='!-f' => matched

rewrite '/a/b/c/index.shtml' -> '/a/b/c/index.shtml/' => slash is appended at the end even though it is a file not a directory

</code>

Appreciate any help.

Thanks
 
tewari68 said:
I have to write a rewrite rule whereby if a url does not have a trailing slash I need to append the trailing slash.
Why?

Servers will do that automagically, (internally with a 302 response)

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top