簡體   English   中英

通過編輯.htaccess文件手動在Wordpress中進行URL重定向

[英]URL redirection in Wordpress manually by editing .htaccess file

請幫我修復我的一個wordpress問題與URL重定向PHP。

這是我原來的wordpress htaccess文件。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

我想在這里創建自定義URL重定向。 例如,我想重定向頁面,

http://example.com/b/1    >     http://example.com/b?n=1
http://example.com/b/2    >     http://example.com/b?n=2

我正在使用目錄URL類型(將URL顯示為沒有擴展名的目錄)在wordpress設置中的SEO選項。

http://example.com/b頁面內,我使用' include('z.php');包含了另一個php文件include('z.php'); '命令。 Z.php通過重定向的URL讀取來自'/?n=1' URL參數。 我試過下面的解決方案,但沒有運氣..

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^b/([^/]*)$ /b/?n=$1 

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

感謝任何幫助。

編輯

wordpress頭文件可以讀取已翻譯的參數。 我通過在標題中顯示GET參數'n'來檢查它。 但它顯示找不到http://example.com/b/文件

我通過編輯http://example.com/b/頁面內容驗證了這一點。 重寫后不顯示頁面內容。

任何幫助贊賞

編輯

URL可能包含參數中的字符,如下所示。

http://example.com/b/abc_1    >     http://example.com/b?n=abc_1
http://example.com/b/aa_2    >     http://example.com/b?n=aa_2

謝謝你的幫助

乍一看,在我看來它應該是

RewriteRule ^b/([^/]*)$ /?p=$1

Wordpress不知道如何處理url /b?n=X

如果您希望http://example.com/b/abc_1正常工作,則abc_1部分必須與wordpress帖子的slug匹配。

此外,您必須更改settings-> permalink結構以匹配postname或自定義結構,如/b/%postname%

在此輸入圖像描述

在此輸入圖像描述

在此輸入圖像描述

http://example.com/b/1

http://example.com/b?n=1

用這個

RewriteRule ^b/([0-9]+)/?$ b?n=$1 [NC,L]


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^b/([0-9]+)/?$ b?n=$1 [NC,L]
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

在此輸入圖像描述在此輸入圖像描述 測試聽到

更多信息

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^b/([^/]*)$ /b/?n=$1 

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#add below line
RewriteRule ^b/([0-9]+)/$ http://example.com/b?n=$1 [L]
</IfModule>    

我找到了這個問題的新聞相關解決方案。

在word中按下所有請求都會自動轉到index.php。 如果我們創建自定義重寫到另一個頁面,該請求不會通過index.php。 這使得wordpress未識別的請求和wordpress將返回頁面未找到的消息。

因此,我們必須將自定義重寫重定向到index.php而不是永久鏈接。

我用了

RewriteRule ^b/([^/]*)$ index.php?page_id=4&n=$1

此規則將與規則匹配的所有請求重定向到索引頁面。 (我的/b/頁面ID是4)這對我成功。

上面的其他解決方案適用於非wordpress情況。 但我發現wordpress的行為正如我解釋的那樣。

感謝誰試圖回答。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM