【问题标题】:Make htaccess accept domain.com and www.domain.com让 htaccess 接受 domain.com 和 www.domain.com
【发布时间】:2014-02-03 22:36:17
【问题描述】:

如何修改此 htaccess 使其允许 www.domain.com 和 domain.com。现在,当我给 www.domain.com 时,它会将其更改为 domain.com

Options -Indexes
Options +FollowSymLinks

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

RewriteRule ^$ website/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/website%{REQUEST_URI} -f
RewriteRule .* website/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* website/index.php?q=$0 [QSA]

抱歉,对htaccess了解不多

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    只需取出剥离www 的前 301 条规则:

    Options -Indexes
    Options +FollowSymLinks
    
    RewriteEngine on
    
    RewriteRule ^$ website/index.php [L]
    
    RewriteCond %{DOCUMENT_ROOT}/website%{REQUEST_URI} -f
    RewriteRule .* website/$0 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* website/index.php?q=$0 [L,QSA]
    

    【讨论】:

    • 感谢您的回复,但它仍在将网址从 www.domain.com 更改为 domain.com。
    • 您能否在新浏览器中尝试此操作以避免缓存问题。
    • 很高兴知道它成功了。是的 301 状态被浏览器积极缓存。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多