2013-06-29 38 views
1

我想從WordPress的URLS刪除index.php。WordPress的永久鏈接與ISAPI重寫2

我有這樣的代碼在我的httpd.ini文件

[ISAPI_Rewrite] 

RewriteCond Host: domain\.com 
RewriteRule (.*) http\://www.domain.com$1 [I,RP] 

RewriteRule /(?!index\.php)([^/.]+)/ /index.php/$1 [I] 

RewriteRule /(?!index\.php)([^/.]+) /index.php/$1 [I,L] 

這工作,但只針對類別,例如domain.com/gear作品,但domain.com/gear/post沒有。

我發現這個職位,但我不能真正遵循它http://www.helicontech.com/forum/14820-Wordpress_Permalinks_for_ISAPI_Rewrite_2.html

有什麼建議?

回答

1

請嘗試以下解決方案:

[ISAPI_Rewrite] 

RewriteCond Host: domain\.com 
RewriteRule (.*) http\://www.domain.com$1 [I,RP] 

RewriteRule /(?!index\.php)([^.]+?)/? /index.php/$1 [I,L] 
0

我知道這是一個老帖子,但如果你仍然需要解決或其他建議,這裏是我工作,爲了什麼情景。

當您嘗試在共享主機環境中運行WordPress時,運行帶有IIS 6服務器的Windows 2003時,您可能會遇到自定義永久鏈接可能無法使用的自定義永久鏈接,例如/%postname%/將返回404錯誤。

如果您的ISP安裝了ISAPI_Rewrite 2並使用ISAPI_Rewrite將流量重定向到不同的站點,這可能適用於您。我縮短了httpd.ini以顯示這是如何工作的WordPress的兩個實例。

這個httpd.ini位於所有網站的根目錄,並且對所有網站都有規定。

[ISAPI_Rewrite] 

### subdomain redirect v2 ### 
RewriteCond Host: (?:.+\.)?your-domain-name1\.com 
RewriteCond URL ^/site-path1/(.*) 
RewriteCond METHOD GET 
RewriteRule ^/site-path1/(.*) /$1 [I,R] 
RewriteCond Host: (?:.+\.)?your-domain-name1\.com 
RewriteCond METHOD POST 
RewriteRule ^/site-path1/(.*) /$1 [I] 
RewriteCond Host: (?:.+\.)?your-domain-name1\.com 
### RewriteRule (.*) /site-path1/$1 [I,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^/wp-admin/?$ /newhat/wp-admin/index.php [I,L] 
RewriteRule ([^.]*) /site-path1/index.php/$1 [I,L] 
RewriteRule (.*) /site-path1/$1 [I,L] 

### subdomain redirect v2 ### 
RewriteCond Host: (?:.+\.)?your-domain-name2\.com 
RewriteCond URL ^/site-path2/(.*) 
RewriteCond METHOD GET 
RewriteRule ^/site-path2/(.*) /$1 [I,R] 
RewriteCond Host: (?:.+\.)?your-domain-name2\.com 
RewriteCond METHOD POST 
RewriteRule ^/site-path2/(.*) /$1 [I] 
RewriteCond Host: (?:.+\.)?your-domain-name2\.com 
### RewriteRule (.*) /site-path2/$1 [I,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^/wp-admin/?$ /newhat/wp-admin/index.php [I,L] 
RewriteRule ([^.]*) /site-path2/index.php/$1 [I,L] 
RewriteRule (.*) /site-path2/$1 [I,L] 

### RewriteRule (.*) /site-path2/$1 [I,L]中註釋掉的版本是修改前的原始ISP配置的最後一行。我插入了4條新線剛剛收到:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^/wp-admin/?$ /newhat/wp-admin/index.php [I,L] 
RewriteRule ([^.]*) /site-path2/index.php/$1 [I,L] 

SO link解釋重寫規則。

我對該行RewriteRule ([^.]*) /site-path2/index.php/$1 [I,L]的理解是,對於任何不包含句點的網址,請將其重寫爲附加index.php。這就是爲什麼它需要在(.*)線之前完成一切。

管理工具欄,如果顯示它有一個鏈接到/wp-admin/沒有指定index.php哪個規則RewriteRule ^/wp-admin/?$ /newhat/wp-admin/index.php [I,L]

另一篇文章/網址與這有助於爲online Apache mod_rewrite測試儀。