invisible mod_rewrite is not always invisible!? (“www” and “without subdomain”)

前端 未结 1 892
一向
一向 2020-12-22 06:32

My site is on a host using cPanel 11.

Unfortunatly it redirects both \"www.e-motiv.net\" and \"e-motiv.net\" to public_html. I want resp. public_htm

相关标签:
1条回答
  • 2020-12-22 07:06

    This is because of mod_dir. mod_dir adds the tailing slashed to urls that map to directories. mod_dir is not aware of these 'virtual urls' created with mod_rewrite.

    So either disable this behavior by using

    DirectorySlash Off
    

    This will however make requests to www.example.com/folder result in a 404 not found. You can fix this with some rewriterule though. So the complete solution would be something like:

    DirectorySlash Off
    #www dir only
    RewriteCond %{DOCUMENT_ROOT}/$0 -d
    RewriteRule ^www/(.+[^/])$ /$1/ [R,L]
    #other dirs
    RewriteCond %{DOCUMENT_ROOT}/$0 -d
    RewriteRule ^(.+[^/])$ /$1/ [R,L]
    
    0 讨论(0)
提交回复
热议问题