2013-01-24 19 views
1

我正在從Mediawiki的我的網站,以Wordpress和想重定向此頁:MEDIAWIKI改寫爲外部網站

http://wecheck.org/wiki/Aaron_Swartz

此頁:

http://newslines.org/wiki/category/computer-people/aaron-swartz/

目前。 htaccess我有

Options +FollowSymlinks 
RewriteEngine on 

RewriteCond %{QUERY_STRING} ^title=Aaron_Swartz$ 
RewriteRule ^/w/index\.php$ http://newslines.org/wiki/category/computer-people/aaron-swartz/? [L,R=301] 


RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L] 
RewriteRule ^/?$ %{DOCUMENT_ROOT}/w/index.php [L] 

第二部分爲mediawiki製作漂亮的URL。我已經嘗試了很多很多變體,但是我根本無法完成它。最受讚賞的任何幫助。

更新:使用給定的解決方案的日誌文件。什麼是.phtml?

[24/Jan/2013:22:01:00 +0000] init rewrite engine with requested uri /wiki/Aaron_Swartz 
[24/Jan/2013:22:01:00 +0000] (1) pass through /wiki/Aaron_Swartz 
[24/Jan/2013:22:01:00 +0000] (1) [perdir /var/www/] pass through /var/www/w/wiki.phtml 
[24/Jan/2013:22:01:00 +0000] (3) [perdir /var/www/] add path info postfix: /var/www/w/wiki.phtml -> /var/www/w/wiki.phtml/Aaron_Swartz 
[24/Jan/2013:22:01:00 +0000] (3) [perdir /var/www/] strip per-dir prefix: /var/www/w/wiki.phtml/Aaron_Swartz -> w/wiki.phtml/Aaron_Swartz 
[24/Jan/2013:22:01:00 +0000] (3) [perdir /var/www/] applying pattern '^wiki/Aaron_Swartz$' to uri 'w/wiki.phtml/Aaron_Swartz' 
[24/Jan/2013:22:01:00 +0000] (3) [perdir /var/www/] add path info postfix: /var/www/w/wiki.phtml -> /var/www/w/wiki.phtml/Aaron_Swartz 
[24/Jan/2013:22:01:00 +0000] (3) [perdir /var/www/] strip per-dir prefix: /var/www/w/wiki.phtml/Aaron_Swartz -> w/wiki.phtml/Aaron_Swartz 
[24/Jan/2013:22:01:00 +0000] (3) [perdir /var/www/] applying pattern '^w/index\.php$' to uri 'w/wiki.phtml/Aaron_Swartz' 
[24/Jan/2013:22:01:00 +0000] (1) [perdir /var/www/] pass through /var/www/w/wiki.phtml 

回答

1

記住表明MediaWiki甚至看到請求之前Apache指令像RewriteRule應用。因此,您當前的規則應適用於http://wecheck.org/w/index.php?title=Aaron_Swartz,但不適用於http://wecheck.org/wiki/Aaron_Swartz

實際上,規則將不起作用,因爲您的正則表達式以/開頭,但在.htaccess上下文中,在應用重寫規則之前刪除了前導斜槓(或任何您設置的RewriteBase)。

因此,固定這兩個問題,你需要的是這樣的:

Options +FollowSymlinks 
RewriteEngine On 
RewriteBase/

# match the short URL of the page: 
RewriteRule ^wiki/Aaron_Swartz$ http://newslines.org/wiki/category/computer-people/aaron-swartz/ [R=301,L] 

# optional: also match the long version of the URL: 
RewriteCond %{QUERY_STRING} ^title=Aaron_Swartz$ 
RewriteRule ^w/index\.php$ http://newslines.org/wiki/category/computer-people/aaron-swartz/ [R=301,L] 

編輯:根據您的日誌文件,它看起來像你有一個wiki.phtml文件在你的網絡服務器Apache自動解析從/wiki/開始的任何URL路徑。

一種解決方法是將您的重寫規則移到主要的Apache配置中,在這些映射完成之前他們將運行它們;另一種更直接的方式是隻改變上面的第一個重寫規則:

# match the short URL of the page: 
RewriteRule ^wiki\.phtml/Aaron_Swartz$ http://newslines.org/wiki/category/computer-people/aaron-swartz/ [R=301,L] 

甚至:

# match the short URL of the page: 
RewriteRule ^wiki(\.phtml)?/Aaron_Swartz$ http://newslines.org/wiki/category/computer-people/aaron-swartz/ [R=301,L] 
+0

我嘗試這樣的代碼,但是當我去http://wecheck.org/wiki/Aaron_Swartz頁面不重定向。還有一點奇怪的是,當我將漂亮的網址註釋掉並且只使用您提供的代碼時,它們仍然出現。是否有某種我缺少的緩存(我禁用了所有可以找到的mediawiki緩存並正在隱身模式下訪問該頁面)。 –

+0

這很奇怪。看起來你在亞馬遜EC2上,所以可能你正在運行你自己的網絡服務器,而不是使用共享主機;也許有一個覆蓋你的.htaccess的全局Apache配置文件? –

+0

我也在虛擬主機目錄中將「AllowOverride None」更改爲「AllowOverride All」,但仍然沒有任何結果。 –