2015-04-23 57 views
1

我試圖將文件夾重定向到文件。 我想重定向:Mod_Rewrite文件到.htaccess中的子文件夾

www.mysite.com/category/customername

www.mysite.com/category/customername/

TO

www.mysite.com/category.php?customer=customername

這是工作,但 「客戶」 變成 「customername.php」,而不是 「客戶」

Options +FollowSymLinks 
RewriteEngine On  
RewriteRule ^category/(.*)$ category.php?customer=$1 [L] 

我怎麼能通過.htaccess刪除「.php」? 謝謝!

回答

2

您可以使用:

Options +FollowSymLinks -MultiViews 

RewriteEngine On  
RewriteRule ^category/([\s\w-]+)/?$ category.php?customer=$1 [L,NC,QSA] 
+0

嗯不行。不工作: RewriteRule^category /(\ w +)$ category.php?customer = $ 1 [L,NC,QSA] – Davide

+0

「NC」和「QSA」是什麼意思?美元后需要問號? – Davide

+0

嗨。當有一些空格或減號( - )時,這不起作用。這是正常的嗎? – Davide

0

謝謝anubhava,我必須做一個動態規則:

RewriteRule ^(.+[^/])/(\w+)/?$ $1.php?customer=$2 [L] 

測試時間

www.mysite.com/category_1/customer AND www.mysite.com/category_1/customer/ www.mysite.com/category_2/customer AND www.mysite.com/category_2/customer/ www.mysite.com/category_X/customer和 www.mysite.com/category_X/customer/

再見