0

处理本地设置。在重写 URL 以使其看起来不错时发现了这个问题我有部门、类别和产品列表....当我单击其中一个部门时,URL 被重写

Project /index.php?departmentId=1 to
Project/deptname-d1

And it displays the associated categories with tat department the twist is when one of the category is selected server throws object not found The selected URL was not found on server the link on referring page seems to be wrong or outdated The URL before rewriting would be

Project/index.php?departmentId=1&CategoryId=2

url 需要的格式是 Project /deptname-d1/catname-c2 htacess 中的正则表达式是这样的 Options +FollowSymLinks RewriteEngine on RewriteBase /project RewriteCond %{THE_REQUEST} ^GET.*/index.(php|html?)\ HTTP RewriteRule ^(. )index.(php|html?)$ $1 [R=301,L] #rewrite 部门 RewriteRule 的规则 ^. ?-d([0-9]+)/page-([0-9]+)/?$ index.php? DepartmentId=$1&Page=$2[L] RewriteRule ^. ?-d([0-9]+)/?$ index.php?DepartmentId=$1[L] #rules for category RewriteRule ^. -d([0-9]+)/^. -c([0-9]+)/page-([0-9]+)/?$ index.php?DepartmentId=$1&CategoryId=$2&Page=$3[L] RewriteRule ^. -d([0-9]+)/^.c([0-9]+)/?$ index.php?DepartmentId=$1&CategoryId=$2 [L] #rewrite rules for product Rewriterule ^. ?-p([0-9]+)/?$ index.php?productId=$1

在重写之前,以下是首页 localhost/project/index.php 的 url localhost/project/?部门首页 localhost/project/index.php 的DepartmentId=x?部门页面 localhost/project/index 的DepartmentId=x&page=z。 php?DepartmentId=x&CategoryId=y 用于类别首页 localhost/project/index.php?DepartmentId=xCategoryId=y&page=z 用于类别页面 localhost /project/ProductId=Q 这些是输入 URL,它们将被重写为以下形式 localhost/project/ 用于首页 localhost/project/department-name-dx/ 用于部门首页 localhost/ project/department-name-dx/page-z/ 用于部门页面 localhost/project/department-name-dx/category-name-cy/ 用于类别前端 localhost/project/department-name-dx/category-name-cy/ page-z 用于类别页面

Please note tat department and product related regex are working fine only the category page is acting weird can someone explain wats going wrong 
4

1 回答 1

0

你的正则表达式是错误的。你不能放在^你的正则表达式中间。尝试这个:

RewriteEngine On

RewriteRule ^.*?-d([0-9]+)/.*?-c([0-9]+)/page-([0-9]+)/?$ index.php?DepartmentId=$1&CategoryId=$2&Page=$3 [L,QSA]
RewriteRule ^.*?-d([0-9]+)/.*?c([0-9]+)/?$ index.php?DepartmentId=$1&CategoryId=$2 [L,QSA]

我建议您在问题中提供所有输入 URL。

于 2013-11-04T14:51:31.553 回答