RewriteCond无法正常工作

时间:2014-10-15 06:34:28

标签: regex apache .htaccess mod-rewrite redirect

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/Home_Page/sort/(all|action|romance|thriller|crime|sci-fi)/(1|2|3|4|5)
RewriteRule  ^([A-Za-z-]+)/([A-Za-z0-9-]+)/([0-9])$  kl.php?genre=$2&page_no=$3 [NC] [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/Home_Page/sort/(all|action|romance|thriller|crime|sci-fi) 
RewriteRule  ^([A-Za-z-]+)/([A-Za-z0-9-]+)$  kl.php?genre=$2 [NC] [L]

请求uri传递所需的查询字符串

if reruest uri is /Home_Page/sort/(all|action|romance|thriller|crime|sci-fi) rewrite to ^([A-Za-z-]+)/([A-Za-z0-9-]+)$  kl.php/?genre=$2
if request uri is  /Home_Page/sort/(all|action|romance|thriller|crime|sci-fi)/([0-9])$ rewrite to ^([A-Za-z-]+)/([A-Za-z0-9-]+)$  kl.php/?genre=$2&page_no=$3

2 个答案:

答案 0 :(得分:0)

您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /index\.php\?genre=([^\s&]+)&page_no=([^\s&]+) [NC]
RewriteRule ^ homepage/%1/%2? [R=302,L]

RewriteRule ^homepage/([^/]+)/([0-9]+)/?$ index.php?genre=$1$page_no=$2 [L,QSA,NC]

答案 1 :(得分:0)

RewriteEngine On
RewriteBase /Home_Page/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/Home_Page/sort/(all|action|romance|thriller|crime|sci-fi)$
RewriteRule  ^([A-Za-z-]+)/([A-Za-z0-9-]+)$  kl.php?genre=$2 [NC] [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/Home_Page/sort/(all|action|romance|thriller|crime|sci-fi)/([0-9]+)$
RewriteRule ^sort/([^/]+)/([0-9]+)/?$ index.php?genre=$1$page_no=$2 [L,QSA,NC]