Search code examples
.htaccessurlmod-rewritekohana

Double slash in url after domain name [Kohana]


I have a problem with URLs in Kohana framework.

When I type mydomain.xyz/admin that redirect to mydomain.xyz//admin and return some errors from Kohana core.

Here is a part of my .htacces:

RewriteEngine On
RewriteBase /

RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L]

###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ $1/ [R=301,L]

RewriteRule ^(.*)public_html/index.php/(.*)$ http://mysite.xyz/$1$2 [R=301,L]

That problem has appeared after move site from other server.


Solution

  • Have it this way:

    DirectorySlash Off
    RewriteEngine On
    RewriteBase /
    
    ###### Add trailing slash (optional) ######
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
    
    RewriteCond %{REQUEST_METHOD} !POST
    RewriteRule ^(.*)public_html/index.php/(.*)$ /$1$2 [R=301,L,NE]
    
    RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|media)
    RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L,QSA]
    

    Make sure to clear your browser cache before testing this change.