2014-01-10 43 views
0

我有WordPress的下一個網站,我創建了一個新的頁面www.foo.com/section/WordPress的&的.htaccess

的想法是創建一個像www.foo.com/param1/type一個固定鏈接/參數2,用的.htaccess使用重寫規則:www.foo.com/section/?var1=param1 & VAR2 =參數2 & VAR3 =類型

RewriteEngine on 
Options +FollowSymlinks 
RewriteRule ^([a-z0-9_\s-.()&]+)/section1/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section1 
RewriteRule ^([a-z0-9_\s-.()&]+)/section2/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section2 

我得到了它在我的舊網站,但在工作WordPress崩潰。

#My rules -> copy&paste 
RewriteRule ^([a-z0-9_\s-.()&]+)/section1/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section1 
RewriteRule ^([a-z0-9_\s-.()&]+)/section2/([a-z0-9]+)$ /section/?var1=$2&var2=$1&var3=section2 
# 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的404頁

我在這裏讀的幾個問題,但沒有人幫助我。

感謝您的時間和問候,

R.

1月13日

我創建了一個簡單的測試,以檢查它。

新的結構可與測試用例沒有問題:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteRule ^lol/$ project/ [L] #Rule 1 
RewriteRule ^foo/$ test/ [L] #Rule 2 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 
  1. 規則1,我創建了一個WordPress的根的子文件夾,命名爲「項目」有呼應的index.php「嗨爸爸「,當輸入www.foo.com/lol/時,它會加載該腳本並回應該單詞。
  2. 規則2,我創建了一個新的WordPress頁面,www.foo.com/test/ 用一個簡單的字符串來顯示,但是當我寫www.foo.com/foo/時,它給了我錯誤404似乎重定向到一個wp頁面並不像我預期的那樣工作。

免責聲明:當然www.foo.com/test/中

現在我stucked。

感謝您的回覆和未來的幫助。

最好的問候,

R.

月14日

我有新的消息:)

的作品新的.htaccess是:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteRule ^([a-z0-9_\s-.()&]+)/alternator/([a-z0-9]+)$ ?page_id=554&supplier=$1&reference=$2&ref_type=A [L] 
RewriteRule ^([a-z0-9_\s-.()&]+)/starter_motor/([a-z0-9]+)$ ?page_id=554&supplier=$1&reference=$2&ref_type=M [L] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 

而是重定向到「elecfinder /」在.htaccess我指向「?page_id = 554」,至少它d oesn't給我錯誤440

我正在開發交流發電機和起動機電機網。

我有一個網址是http://www.elecfinder.com/hitachi/starter_motor/s114850真的是http://www.elecfinder.com/info/?supplier=hitachi&ref_num=M&reference=s114850,在這裏我加載參考信息。

http://wp.elecfinder.com/elecfinder/?reference=s114850&supplier=hitachi&ref_type=M是wp中的web,所以我的想法是將http://wp.elecfinder.com/hitachi/starter_motor/s114850/重定向到此。

現在我能夠重定向到http://wp.elecfinder.com/hitachi/starter_motor/s114850http://wp.elecfinder.com/elecfinder/?page_id=554&supplier=hitachi&ref_num=M&reference=s114850有2個問題:

  1. 它改變URL來代替http://wp.elecfinder.com/elecfinder/保持wp.elecfinder.com/hitachi/starter_motor/s114850
  2. 錯過了GET參數「reference」,「supplier」和「ref_type」

謝謝你的時間。

最好的問候,

R.

+0

你的規則在'RewriteEngine On'之前# – anubhava

回答

1

嘗試以下操作:

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

RewriteRule ^([a-z0-9_\s-.()&]+)/(section1|section2)/([a-z0-9]+)$ section/?var1=$1&var2=$3&var3=$2 [L] 

RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 
# END WordPress 

始終把你的規則後RewriteEngine敘述上。 而且,在這種情況下(WordPress),請務必在規則之前 WordPress規則(在這裏將所有內容重定向到index.php,因爲WordPress有一個前端控制器,並且它自己管理重寫)。

+0

它與wordpress項目的外部文件夾一起工作,但如果我嘗試重定向到wp頁面,則失敗。 我在開始時添加了更多信息。 謝謝:) – reverendocabron

+0

在你的測試中,它應該是^ foo/$(帶斜線),因爲你試圖訪問www.foo.com/foo/。否則,如果你想訪問www.foo.com/foo(沒有結尾斜線),你應該有^ foo $ –

+0

這是一個錯誤的複製字符串。在.htaccess中沒關係。 – reverendocabron