簡體   English   中英

htaccess基於類別的重定向

[英]htaccess category based redirect

我要執行以下重定向:
example.com/a/b/c ===> example.com/index.php?p=a/b/c
example.com/d/e/f ===> example.com/index.php?p=d/e/f
example.com/area2/b/c ===> example.com/index_area2.php?p=b/c
example.com/area2/d/e ===> example.com/index_area2.php?p=d/e

這就是我現在所擁有的:

RewriteRule ^area2(.*)$ /index_area2.php?p=$1 [L,QSA]  
RewriteRule ^(.*)$ /index.php?p=$1 [L,QSA]

我收到內部服務器錯誤。 這是怎么了 每個規則單獨起作用。

您收到500錯誤,因為您的規則導致任何RewriteCond無限循環。 有這種方式:

RewriteEngine On
RewriteBase /

# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f
# skip them from rules below
RewriteRule ^ - [L]

RewriteRule ^area2/(.+)$ index_area2.php?p=$1 [L,QSA,NC]

RewriteRule ^(.+)$ index.php?p=$1 [L,QSA]

暫無
暫無

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

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