.htaccess重写网址显示404未找到

时间:2016-01-14 10:35:25

标签: .htaccess

我想更改此网址

domain.com/adsbycat/sub_category.php?category=car-and-buses&category_id=1&sub_category=Car

domain.com/car-and-buses/1/Car

我写这段代码来做这件事

RewriteEngine On  
RewriteBase /domain.com/    
RewriteRule ^adsbycat/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ adsbycat/sub_category.php?category=$1&category_id=$2&sub_category=$3

但是当我请求新网址时,它显示 404 not found 。请修改此代码。

1 个答案:

答案 0 :(得分:2)

在网站根.htaccess中使用此规则重写domain.com/car-and-buses/1/Car

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/[^/]+/(.+)$ adsbycat/sub_category.php?category=$1&category_id=$2&sub_category=$3 [NC,L,QSA]