簡體   English   中英

使用.htaccess將地址從xxx.example.com重寫為example.com/xxx/

[英]Use .htaccess to rewrite address from xxx.example.com to example.com/xxx/

我正在尋找一種方法,以便用戶可以通過鍵入xxx.example.com來訪問他們的頁面,然后轉發到他們各自的WordPress帖子。

現在我的網站上已經有兩個重寫功能了:(不是我寫的)

要在任何地方使用https:

 #Rewrite everything to https
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]

和WordPress:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

現在,WordPress函數似乎將example.com/post_title翻譯成相應的帖子。

但是如何重寫它以便將post_title.example.com翻譯成相應的帖子?

如果可能,仍然顯示xxx.example.com而不是example.com/xxx

以下應該有效,將.htaccess更改為:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# Rewrite to https
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]

# This rewrite rule will only be used if
# we have an empty query string and the http host does not start with www
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^$ http://%{HTTP_HOST}/%1 [L]

# The default wordpress rewrite rule
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

為此,我想您需要在wordpress安裝中設置正確的永久鏈接結構:

在此輸入圖像描述

暫無
暫無

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

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