2017-07-18 101 views
0

我知道如何更改PHP中的網址,但我不是WordPress的專家。如何在wordpress中使用.htaccess更改GET變量以獲得漂亮的URL

我有這個網址:

domain.com/parent-page/child-page-here/?id=SomeText

,我想這

domain.com/parent-page/child-page-here/Some文字:

我改變.htaccess但它不在這裏工作是我的.htaccess代碼

# 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 
RewriteEngine On 
RewriteRule ^parent-page/child-page/([0-9a-zA-Z]+) parent-page/child-page/?id=$1 [NC,L] 

回答

0

不需要使用.htaccess,因爲Wordpress自帶了所需的功能。您所要做的就是將管理儀表板中的永久鏈接更改爲here

+0

我使用的是來自parmalink的post-name。我發送id =「text」中的數據並從自定義頁面$ _GET [''id「]中獲取數據,並將此值發送到數據庫以獲得結果 –

+0

可以請您告訴如何從.htaccess文件更改URL並執行此操作現在RewriteRule^parent-page/child-page /([a-zA-Z0-9 - ] +)/?$ parent-page/child-page/index.php /?id = $ 1 [L]但它不工作 –

0

@mapmalith是正確的,使用WordPress,您可以簡單地更改設置中的固定鏈接。

但是,如果出於某種原因你無法做到這一點,那麼你可以使用你的.htaccess文件中的以下內容:

RewriteEngine On 
RewriteRule ^parent-page/child-page-here/([^/]*)$ /parent-page/child-page-here/?id=$1 [L] 

它會使你的以下網址:domain.com/parent-page/child-page-here/SomeText。在測試之前,請確保清除緩存。

很明顯,您需要將目錄重命名爲正確的名稱。

+0

我已經選擇名稱後形式的儀表板和我只是想你的代碼它不工作了給我內部服務器錯誤 –

+0

這是我的.htaccess文件(#BEGIN WordPress的 RewriteEngine敘述在 重寫規則^飛機─ RewriteRule^index \ .php $ - [L] RewriteCase/ RewriteBase/ RewriteRule^index \ .php $ - [L] RewriteCond/gallery_files/aircraft-gallery-class /([^ /] *)$ aircraft-gallery/aircraft-gallery-class /?id = %{REQUE ST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteRule。 /index.php [L] #結束WordPress的) –

+0

你在那裏..? –