Forum Moderators: phranque
I am looking to create a simple mod_rewrite, although don't know where to start. I needs to add a / onto the end of folder URL's in the address bar.
e.g.
www.sweaters.com/knitted
would rewrite to
www.sweaters.com/knitted/
It cant just add / onto the end of everything though, just subfolders.
e.g.
www.sweaters.com/knitted/new
or
www.sweaters.com/knitted/test.html
should not have a / added to the end of them
I also need it to be as generic as possible, preferably not mentioning www.sweaters.com or /knitted/ so that it can be re-used on other websites or folders.
Thanks for any help you can offer me. If you only know how to do part of it, please post your ideas so that we can solve it together.
Regards,
Rodger
www.example.com/example
type addresses to
www.example.com/example/
(you could write an expression to rewrite those and not anything that ended in .htm, .html, .php etc)
but if you need to differentiate between
www.example.com/knitted
www.example.com/new
then it would not be possible
if you structure is only one folder deep, then it would be possible to rewrite all url's of the type
example.com/firstlevel
to
example.com/firstlevel/
this is very easy using a generic regular expression
Welcome to WebmasterWorld!
If you are getting a 500-Server Error, then check your server error log! It will often tell you exactly what is wrong.
Externally redirect any request to first-level subdirectories (only) with no trailing slash and not containing a "." to same URL with trailing slash:
RewriteRule ^([^/]+/[^./]+)$ http://www.yourdomain.com/$1/ [R=301,L]
-----
I initially misunderstood your requirements and wrote the following. Maybe it will help someone else...
Externally redirect any request one or more subdirectories deep with no trailing slash and not containing a "." to same URL with trailing slash:
RewriteRule ^(.+/[^./]+)$ http://www.yourdomain.com/$1/ [R=301,L]
-----
Both examples above are intended for use in .htaccess. For use in httpd.conf, add a leading slash to the RewriteRule patterns.
Jim