Forum Moderators: phranque
I am just starting out with mod_rewrite, overwhelmed by the voodoo docs :) Found a lot of useful stuff here.
What I am doing is a simple subdomain->subdirectory rewrite. The rewrite works fine, the only thing that I would like to tweak is the following: when a request comes for a directory (and the corresponding index.html is served), the address in the browser address bar changes to include the subdirectory.
Example: I am rewriting [new.com...] to the folder "new" on [old.com....] If a request is made for [new.com...] it's served correctly from [old.com...] but the address in the browser still says [new.com...] (perfect!). However, if a request is made for [new.com...] , then the address in the browser changes to [new.com...] , and then the corresponding index.html is served. Is this somehow due to an internal request apache makes? I tried adding on an "index.html" myself for directory requests, but it didn't work...
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ $1/index.html
My main rewrite is the usual (.htaccess):
RewriteCond %{HTTP_HOST} new\.com$ [NC]
RewriteCond %{REQUEST_URI}!^/new/.*
RewriteRule ^(.*)$ /new/$1 [L]
Any help greatly appreciated! Thank you!
By adding this before other rules, it should go away.
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/*(.+/)?([^.]*[^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
If you want to cover both http and https:
Options +FollowSymlinks
RewriteEngine On
RewriteCond s%{HTTPS} ^((s)on¦s.*)$ [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http%2://%{HTTP_HOST}/$1$2/ [L,R=301]Note: These codes are very efficient compared to the code with '-d' check,
but they won't work with directories that have a dot (period) in it.
(ex. /a_directory.name/)