htaccess重写URI上的例外情况

时间:2013-11-26 09:32:21

标签: php apache .htaccess mod-rewrite

我想重写以下网址:

http://www.web.de/productCat1 - >将Var productCat1传递给productCat.php
http://www.web.de/productCat1/product20 - >将Var productCat1 + Var product20传递给products.php
http://www.web.de/shop - >文件存在时什么也不做 http://www.web.de/contact - >文件存在时什么都不做

到目前为止,我有这个:

Options +FollowSymLinks -MultiViews  
RewriteEngine On  
RewriteBase /  

# PHP to NO Extension  
RewriteCond %{REQUEST_FILENAME}.php -f  
RewriteCond %{REQUEST_URI} !/$  
RewriteRule ^(.*)$ $1\.php

#catch all products
RewriteCond %{REQUEST_URI} ^/([^/]+/[^/]+)/{0,1}$
RewriteRule ^([^/]+/[^/]+)/{0,1}$ /products.php?rw=1&url=$1/$2 [L,QSA]

#catch all categories
RewriteCond %{REQUEST_URI} !^/(shop|contact)$
RewriteRule ^([^/]+)$ /productCat.php?rw=1&url=$1/$2 [L,QSA]

经过几次尝试后,我仍然收到500内部服务器错误。

1 个答案:

答案 0 :(得分:0)

尝试:

Options +FollowSymLinks -MultiViews  
RewriteEngine On  
RewriteBase /  

# PHP to NO Extension  
RewriteCond %{REQUEST_FILENAME}.php -f  
RewriteCond %{REQUEST_URI} !/$  
RewriteRule ^(.*)$ $1\.php

#catch all products
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+/[^/]+)/?$ /products.php?rw=1&url=$1 [L,QSA]

# catch all categories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/? /productCat.php?rw=1&url=$1 [L,QSA]