簡體   English   中英

Apache htaccess重寫URL規則?

[英]Apache htaccess re-write URL rules?

我想為htaccess中的以下URL創建URL重寫規則。

http://example.com/vedios/category/fun/ -> http://example.com/vedios/category.php?cat=fun

http://example.com/vedios/category/fun/?show=popular -> http://example.com/vedios/category.php?cat=comedy&show=popular

http://example.com/vedios/category/fun/?show=popular&page=2 -> http://example.com/vedios/category.php?cat=comedy&show=popular&page=2

http://example.com/vedios/category/fun/comedy/ -> http://example.com/vedios/category.php?cat=comedy

http://example.com/vedios/category/fun/comedy/?show=popular -> http://example.com/vedios/category.php?cat=comedy&show=popular

http://example.com/vedios/category/fun/comedy/?show=popular&page=3 -> http://example.com/vedios/category.php?cat=comedy&show=popular&page=3

我嘗試了RewriteRule category/([^.]+)/?([^.]+)$ /vedio/category.php?cat=$1&$2 for http://example.com/vedio/category.php?cat=fun&show=popular&page=1但無法正常工作。

請告訴我滿足上述要求的正確URL重寫規則是什么?

該查詢不是RewriteRule指令中檢查的URL路徑的一部分。 您將需要一個RewriteCond指令來執行此操作。

但是,您只需要設置QSA標志,即可將初始查詢字符串附加到新查詢字符串之后:

RewriteRule category/([^.]+)/$ /vedio/category.php?cat=$1 [QSA]

我的正則表達式類別腳本:

/vedio/category/([^.]+)/\?([^.]+)$

這取決於mod_rewrite是評估您的所有URL(服務器+端口+路徑)還是僅評估腳本的路徑。

暫無
暫無

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

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