When I type this \"http://example.com/Hello%20There/\" , it displays the index page wich is : \"http://example.com/Hello%20There/index.html\" .
Well, what I want to
You can make a character optional by appending the ?
quantifier to it like this:
RewriteRule ^([^/]+)/?$ $1/index.html
Now both /foobar
and /foobar/
would be rewritten to /foobar/index.html
.
But it would be better if you use just one spelling, with or without the trailing slash, and redirect the other one:
# remove trailing slash
RewriteRule (.+)/$ /$1 [L,R=301]
# add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ /$1/ [L,R=301]
These rules either remove or add a missing trailing slash and do a permanent redirect.
I had the same problem, but I was using mod_alias to set up a subsite. Turns out, I needed to make a second alias without the trailing slash so that it would work correctly. Looked something like this:
Alias /forum/ "/var/www/forum"
Alias /forum "/var/www/forum"
<Directory "/var/www/forum">
Options FollowSymlinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
In Ubuntu, I had to edit the /etc/apache2/mods-enabled/alias.conf file with these lines, then restart apache. Couldn't find this answer anywhere on the web; I just stumbled onto it myself as mod_rewrite wasn't working and the DirectorySlash command didn't help either. I was appending a non-Drupal program as a subsite under a Drupal installation, which is what kicked off all this madness in the first place...
Don't use trailing slash to define an alias.
Both URLs http://example.com/myalias1 and http://example.com/myalias1/ would work fine.
Example:
sudo vi /etc/apache2/apache2.conf
Alias /myalias1 "/path/to/folder1"