Trailing Slash Problem

When I type this symbol http://example.com/Hello%20There/ ", it displays the index page:" http://example.com/Hello%20There/index.html ".

Well, what I want to do when the user enters " http://example.com/Hello%20There " (since the first, except for him, does not have a trailing slash).

I tried many things and specially regexes, but nothing works, because I think the server stops the reg exp process when it finds a space ("% 20" in the url).

I tried this reg exp:

Options +FollowSymLinks 
rewriteEngine On rewriteCond %{REQUEST_URI} ^(.*)\ (.*html)$ 
rewriteRule ^.*$ %1-%2 [E=space_replacer:%1-%2] 
rewriteCond %{ENV:space_replacer}!^$ 
rewriteCond %{ENV:space_replacer}!^.*\ .*$ 
rewriteRule ^.*$ %{ENV:space_replacer} [R=301,L] 

and also put:

DirectorySlash On 

in the module "mod_dir" Apache.

, : - , URL- , $

+5
3

, ? :

RewriteRule ^([^/]+)/?$ $1/index.html

/foobar /foobar/ /foobar/index.html.

, :

# remove trailing slash
RewriteRule (.+)/$ /$1 [L,R=301]

# add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*[^/]$ /$1/ [L,R=301]

, .

+14

, mod_alias . , , . - :

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>

Ubuntu /etc/apache 2/mods-enabled/alias.conf , apache. ; , mod_rewrite , DirectorySlash . , Drupal, Drupal, , ...

+1

.

URL http://example.com/myalias1 http://example.com/myalias1/ .

:

sudo vi /etc/apache2/apache2.conf            

Alias /myalias1 "/path/to/folder1"           
0

All Articles