2017-02-25 50 views
0

.htaccess重寫規則未正常工作 - htaccess的

RewriteEngine On 

RewriteRule ^pg/(.*)$ /manage/product_groups/$1 

我想每個URL與pg/fetchPG作爲第一和第二URL段重定向像

http://website.com/pg/fetchPG?name=Name_here 

http://website.com/manage/product_groups/fetchPG?name=Name_here 

我也想要除此之外的任何URL,應該被重定向到http://website.net

我試圖通過在PHP中編寫一些代碼來做到這一點,但它執行302重定向。所以這不是我想要的。

mod_rewrite的日誌如下

[Sat Feb 25 17:18:03.920251 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc588c0a0/initial] [perdir /var/www/html/] add path info postfix: /var/www/html/pg -> /var/www/html/pg/fetchPG 
[Sat Feb 25 17:18:03.920306 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc588c0a0/initial] [perdir /var/www/html/] strip per-dir prefix: /var/www/html/pg/fetchPG -> pg/fetchPG 
[Sat Feb 25 17:18:03.920314 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc588c0a0/initial] [perdir /var/www/html/] applying pattern '^pg/(.*)$' to uri 'pg/fetchPG' 
[Sat Feb 25 17:18:03.920338 2017] [rewrite:trace2] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc588c0a0/initial] [perdir /var/www/html/] rewrite 'pg/fetchPG' -> 'manage/product_groups/fetchPG' 
[Sat Feb 25 17:18:03.920349 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc588c0a0/initial] [perdir /var/www/html/] add per-dir prefix: manage/product_groups/fetchPG -> /var/www/html/manage/product_groups/fetchPG 
[Sat Feb 25 17:18:03.920363 2017] [rewrite:trace2] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc588c0a0/initial] [perdir /var/www/html/] trying to replace prefix /var/www/html/ with/
[Sat Feb 25 17:18:03.920375 2017] [rewrite:trace1] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc588c0a0/initial] [perdir /var/www/html/] internal redirect with /manage/product_groups/fetchPG [INTERNAL REDIRECT] 
[Sat Feb 25 17:18:03.920959 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] add path info postfix: /var/www/html/manage/product_groups -> /var/www/html/manage/product_groups/fetchPG 
[Sat Feb 25 17:18:03.920976 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] strip per-dir prefix: /var/www/html/manage/product_groups/fetchPG -> product_groups/fetchPG 
[Sat Feb 25 17:18:03.920984 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] applying pattern '(^|/)\\.' to uri 'product_groups/fetchPG' 
[Sat Feb 25 17:18:03.920992 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] add path info postfix: /var/www/html/manage/product_groups -> /var/www/html/manage/product_groups/fetchPG 
[Sat Feb 25 17:18:03.920999 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] strip per-dir prefix: /var/www/html/manage/product_groups/fetchPG -> product_groups/fetchPG 
[Sat Feb 25 17:18:03.921006 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] applying pattern '^(.*)$' to uri 'product_groups/fetchPG' 
[Sat Feb 25 17:18:03.921020 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] add path info postfix: /var/www/html/manage/product_groups -> /var/www/html/manage/product_groups/fetchPG 
[Sat Feb 25 17:18:03.921027 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] strip per-dir prefix: /var/www/html/manage/product_groups/fetchPG -> product_groups/fetchPG 
[Sat Feb 25 17:18:03.921041 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] applying pattern '^' to uri 'product_groups/fetchPG' 
[Sat Feb 25 17:18:03.921055 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] add path info postfix: /var/www/html/manage/product_groups -> /var/www/html/manage/product_groups/fetchPG 
[Sat Feb 25 17:18:03.921063 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] strip per-dir prefix: /var/www/html/manage/product_groups/fetchPG -> product_groups/fetchPG 
[Sat Feb 25 17:18:03.921069 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] applying pattern '^(.*)$' to uri 'product_groups/fetchPG' 
[Sat Feb 25 17:18:03.921085 2017] [rewrite:trace2] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] rewrite 'product_groups/fetchPG' -> 'index.php?/product_groups/fetchPG' 
[Sat Feb 25 17:18:03.921093 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] split uri=index.php?/product_groups/fetchPG -> uri=index.php, args=/product_groups/fetchPG 
[Sat Feb 25 17:18:03.921105 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] add per-dir prefix: index.php -> /var/www/html/manage/index.php 
[Sat Feb 25 17:18:03.921114 2017] [rewrite:trace2] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] strip document_root prefix: /var/www/html/manage/index.php -> /manage/index.php 
[Sat Feb 25 17:18:03.921120 2017] [rewrite:trace1] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc5886330/initial/redir#1] [perdir /var/www/html/manage/] internal redirect with /manage/index.php [INTERNAL REDIRECT] 
[Sat Feb 25 17:18:03.921192 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc58794c0/initial/redir#2] [perdir /var/www/html/manage/] strip per-dir prefix: /var/www/html/manage/index.php -> index.php 
[Sat Feb 25 17:18:03.921202 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc58794c0/initial/redir#2] [perdir /var/www/html/manage/] applying pattern '(^|/)\\.' to uri 'index.php' 
[Sat Feb 25 17:18:03.921211 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc58794c0/initial/redir#2] [perdir /var/www/html/manage/] strip per-dir prefix: /var/www/html/manage/index.php -> index.php 
[Sat Feb 25 17:18:03.921217 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc58794c0/initial/redir#2] [perdir /var/www/html/manage/] applying pattern '^(.*)$' to uri 'index.php' 
[Sat Feb 25 17:18:03.921226 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc58794c0/initial/redir#2] [perdir /var/www/html/manage/] strip per-dir prefix: /var/www/html/manage/index.php -> index.php 
[Sat Feb 25 17:18:03.921240 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc58794c0/initial/redir#2] [perdir /var/www/html/manage/] applying pattern '^' to uri 'index.php' 
[Sat Feb 25 17:18:03.921255 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc58794c0/initial/redir#2] [perdir /var/www/html/manage/] strip per-dir prefix: /var/www/html/manage/index.php -> index.php 
[Sat Feb 25 17:18:03.921262 2017] [rewrite:trace3] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc58794c0/initial/redir#2] [perdir /var/www/html/manage/] applying pattern '^(.*)$' to uri 'index.php' 
[Sat Feb 25 17:18:03.921274 2017] [rewrite:trace1] [pid 8296] mod_rewrite.c(468): [client 39.32.81.36:26799] 39.32.81.36 - - [website.com/sid#7efcd2c4ec80][rid#7efcc58794c0/initial/redir#2] [perdir /var/www/html/manage/] pass through /var/www/html/manage/index.php 
+0

是/ var/www/html等/管理/ product_groups/fetchPG正確的最終路徑? –

回答

2

編輯/日誌:要查看發生了什麼事,在你的服務器的配置文件enable logging for mod_rewrite。讓我知道你是否需要尋求幫助。在文件(可能是httpd.conf)中,找到LogLevel指令並將rewrite:trace2添加到該行。請記住,您必須重新啓動Apache以使日誌記錄生效。

首先,我懷疑你的解決方案是在使用RewriteBase directive。沒有它,很難知道你的替代前綴是什麼。在像.htaccess這樣的文件設置中,可能是因爲替換引導斜槓導致問題。

二,使用the QSA flag追加原來的查詢字符串:

RewriteEngine On 
RewriteBase/
RewriteRule ^pg/(.*)$ manage/product_groups/$1 [QSA] 
+0

我得到404錯誤。不起作用 – Umair

+0

之前的錯誤是什麼?您可能需要使用RewriteBase路徑。另外:你能記錄下去嗎?我是否應該將日誌記錄指令添加到答案中 - 以查看發生了什麼? –

+0

'manage'文件夾中有一個Codeigniter項目。以前我有一些其他的錯誤,現在CodeIgniter的404錯誤。順便說一句,如果我直接把'manage/product_groups'代替'pg'在瀏覽器中,URL的作品。 – Umair