【发布时间】:2011-02-23 22:16:20
【问题描述】:
我正在使用 Apache 2.2 和 mod_rewrite。我想采用以下网址并将它们映射到另一个网址。模式很简单,如下所示:
http://domain/test/ex1.html -> http://domain/app/index.php/content/?name=ex1
我在 .htaccess 文件中尝试了以下内容(放在 docroot 的 /test/ 目录中):
RewriteEngine On
RewriteBase /app/
RewriteRule (.*)\.html index.php/content/?name=$1
和
RewriteEngine On
RewriteRule (.*)\.html /app/index.php/content/?name=$1
我不确定反向引用是否正确,因此设置为 $0 和 $2 但似乎从来没有帮助。
我也尝试将 RewriteLogLevel 设置为 9。
有一个步骤几乎就在那里: 重写 'ex1.html' -> 'index.php/content/?name=ex1'
重写日志的最后一行如下: [perdir /var/www/domain/htdocs/test/] 内部重定向与 /app/index.php/content/ [内部重定向]
如何将其重写为 /app/index.php/content/?name=ex1 ?
编辑 因此,在 docroot 文件中将其用作 .htacces 适用于 RedirectMatch:
RewriteEngine On
RewriteBase /
RedirectMatch ^(.*)/(.*)\.html$ http://domain/app/index.php/content/?name=$2
#this doesnt work - adding to docroot allows for it to pick up but still using test/ex1 rather than just ex1
#RewriteRule ^(.*)\.html$ /app/index.php/content/?name=$1
任何帮助让底层 RewriteRule(目前已被注释掉)工作将不胜感激。
谢谢
【问题讨论】:
标签: apache mod-rewrite