Forum Moderators: phranque
I want to add trailing slashes to my url with mod_rewrite. I found a rule for that and placed it at [localhost...]
RewriteEngine on
RewriteRule ^([a-zA-Z0-9\-_]+)$ $1/ [R]
I want to rewrite:
[localhost...]
to
[localhost...]
But there ist a problem, mod_rewrite rewrites ist to
[localhost...]
and produce a 404. How can I avoid this behavior an get [localhost...] ?
Jeena Paradies
Welcome to WebmasterWorld [webmasterworld.com]!
I would suggest:
RewriteEngine on
# If the URL does not end with a slash
RewriteCond %{REQUEST_URI} !/$
# and the URL does not contain a full stop (Example: inde[b]x.h[/b]tml)
RewriteCond %{REQUEST_URI} !\.
# rewrite it so that it ends with a slash
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
The substitution URL should always contain "http://www.<domain>/" when the [R} flag is used.
Jim
But you had very good Ideas and I have rewriten a little bit:
RewriteEngine on
# If the URL does not end with a slash
RewriteCond %{REQUEST_URI}!/$
# and the URL does not contain a full stop (Example: index.html)
RewriteCond %{REQUEST_URI}!\.
# and the URL is not a directory
RewriteCond %{REQUEST_URI}!-d
# rewrite it so that it ends with a slash
RewriteRule (.*) http://localhost/open/Webs/jeenas-home5/artikel/$1/ [R=301,L]
It works fine now except that if I write:
http://localhost/open/Webs/jeenas-home5/artikel
http://localhost/open/Webs/jeenas-home5/artikel//var/www/open/Webs/jeenas-home5/artikel/
how can I avoid that?
Big thanks to you guys and especially to you jdMorgan!
RewriteEngine on
#RewriteBase /artikel
# If the URL does not end with a slash
RewriteCond %{REQUEST_URI}!/$
# and the URL does not contain a full stop (Example: index.html)
RewriteCond %{REQUEST_URI}!\.
# not artikel
RewriteCond %{REQUEST_URI}!artikel$
# rewrite it so that it ends with a slash
RewriteRule (.*) [localhost...] [R=301,L]
RewriteRule "^([a-zA-Z0-9\-_]+)/" ./artikel.php?artikel=$1