【发布时间】:2014-03-30 05:02:01
【问题描述】:
我的 Web 应用程序的 URL 采用以下形式:
/cms/welcome
/cms/system-admin/groups
/cms/system-admin/standard-lists/accounting/COA
....
....
我正在尝试找到一个正则表达式,将其翻译为:
/cms/index.php?content=welcome
/cms/index.php?content=system-admin/groups
/cms/index.php?content=system-admin/standard-lists/accounting/COA
....
....
我在下面尝试了这个,但它没有给出“在此服务器上找不到请求的 URL /cms/welcome/”,'请求的 URL /cms/system-admin/在此服务器等上找不到组等
RewriteEngine On
RewriteBase /cms
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^/]+)/?$ index.php?content=$1 [L]
我的假设是:^([^/]+)/?$ 应该匹配 /cms/ 之后的任何内容并将其存储在 $1强>。 任何帮助将不胜感激。 以下重写规则也失败了: RewriteRule ^(.*)$ index.php?page=$1
重写规则 ^/?([A-Za-z0-9-/]+)/?$ index.php?page=$1 [QSA,L]
【问题讨论】:
-
第一个问题很好。你花时间标记它,展示你尝试过的东西并说出你的想法和假设。一个小点:你所有的网址都以
,结尾吗?是否应该重写为以;结尾?
标签: regex .htaccess mod-rewrite