2017-10-06 53 views
0

我安裝的WordPress上的/ var/vwww /從blog.example.net的WordPress上的子域和目錄

訪問博客這工作得很好,完美

然後,我也喜歡它是從WWW訪問。 example.net/blog

至於結果,首先,我修改我的Apache虛擬主機條目做別名:

<VirtualHost *:80> 
DocumentRoot /var/www/public_html  
Alias /blog /var/vwww/blog 
</VirtualHost> 

其次,我修改/var/vwww/blog/.htaccess:

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{HTTP_HOST} ^www.example.net$ [NC] 
RewriteRule ^/blog/index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /blog/index.php [L] 

RewriteCond %{HTTP_HOST} ^blog.example.net$ [NC] 
RewriteRule ^/blog/index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

最後,我修改我的WordPress的wp-config.php文件

define('BASE_BLOG_URL', 'http://www.example.net/blog'); 
define('BASE_SITE_URL', 'http://example.net'); 
define('WP_HOME','http://www.example.net/blog'); 
define('WP_SITEURL','http://www.example.net/blog'); 

它適用於網址,如:

  • blog.example.net
  • www.example.net/blog
  • www.example.net/blog/article-slug

而不是

  • blog.example.net/article-slug

上面的網址是以前的工作,但現在我得到錯誤500,請幫助。

+0

爲什麼你想要做的,而不是一個重定向到另一個呢? – janh

+0

歷史原因,大多數SEO和內部鏈接共享已經使用blog.example.net/article-slug 然後現在的要求要求改爲example.net/blog/article-slug並期望兩者同時工作 – exiang

+0

Wouldn儘管重定向足夠了嗎?您仍然可以點擊舊網址並重定向到內容。我已經看到規範標籤配置多次崩潰,並且人們在谷歌以DC結束。 無論如何,你有權訪問錯誤日誌以查看實際錯誤是什麼? – janh

回答

0

我想我解決了它

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{HTTP_HOST} ^blog.example.net$ [NC] 
RewriteRule ^(.*)$ https://www.example.net/blog/$1 [R=301,L,NE] 

RewriteCond %{HTTP_HOST} ^www.example.net$ [NC] 
RewriteRule ^/blog/index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /blog/index.php [L] 
</IfModule>