Forum Moderators: phranque

Message Too Old, No Replies

Mod_rewrite to behave like directory

         

Speeps

12:51 am on Apr 4, 2006 (gmt 0)

10+ Year Member



Currently I have the following mod_rewrite:

RewriteRule ^dir/(.*)\/?$ /dir.html?cat=$1 [L]

The problem is the page is viewable via the following urls:

/dir/WWW
and
/dir/WWW/ (note the end slash)

I want it to permenently behave like the latter, with the slash. Mainly because it can contain more directories, e.g.: /dir/WWW/Forums/

I know I could make the rule as follows:

RewriteRule ^dir/(.*)/$ /dir.html?cat=$1 [L]

This however breaks when Yahoo tries spidering the site, as it stips the end slash!

Has anybody got a work around?

jdMorgan

1:52 am on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something like:

# if no filetype or trailing slash in URI
RewriteCond %{REQUEST_URI} !(\.[a-z0-9]+¦/)$
# add a slash (301 redirect to fix search listings)
RewriteRule (.*) http://www.example.com/$1/ [R-301,L]
#
# Rewrite dir/ requests to dir.html
RewriteRule ^dir/(.+)/$ /dir.html?cat=$1 [L]

should do it.

Replace the broken pipe "¦" character with a solid pipe before use. Posting on this forum modies pipe characters.

Jim