簡體   English   中英

如何將domain.com重寫為www.domain.com

[英]How to rewrite domain.com to www.domain.com

我正在嘗試編輯apache2.conf以將domain.com重寫為www.domain.com:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # if request is not for a file/directory 
    RewriteCond %{SCRIPT_FILENAME} -d [OR]
    RewriteCond %{SCRIPT_FILENAME} -f
    # then skip from rewrites
    RewriteRule ^ - [L]

    # add www to hostname
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{SERVER_ADDR} !=127.0.0.1
    RewriteCond %{SERVER_ADDR} !=::1
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    # forward all the requests to `/index.php
    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>

我看不到任何明顯的錯誤,但是重寫不起作用。 有任何想法嗎?

對規則進行細微更改:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /

# add www to hostname
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_ADDR} !=127.0.0.1
RewriteCond %{SERVER_ADDR} !=::1
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# if request is not for a file/directory 
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
# then skip from rewrites
RewriteRule ^ - [L]

# forward all the requests to `/index.php
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM