![](/img/trans.png)
[英]how to 301 example.com/xxx/feed to example.com/xxx/ in htaccess
[英]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.