modrewrite RewriteRule问题
我正在使用 Apache 2.2 和 mod_rewrite。我想获取以下网址并将它们映射到另一个网址。模式很简单,如下所示:
http://domain/test/ex1.html -> http://domain/app/index.php/content/?name=ex1< /a>
我在 .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=前 1 ?
编辑 因此,在 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(当前已注释掉)正常工作的帮助将不胜感激。
谢谢
I am using Apache 2.2 and mod_rewrite. I would like to take the following urls and map them to another url. The pattern is simple and like this:
http://domain/test/ex1.html -> http://domain/app/index.php/content/?name=ex1
I tried the following in an .htaccess file (place in /test/ directory in docroot):
RewriteEngine On
RewriteBase /app/
RewriteRule (.*)\.html index.php/content/?name=$1
and
RewriteEngine On
RewriteRule (.*)\.html /app/index.php/content/?name=$1
I wasn't sure if the backreference was correct so set to $0 and $2 but never seemed to help.
I also tried setting the RewriteLogLevel to 9.
There is a step where it is almost there:
rewrite 'ex1.html' -> 'index.php/content/?name=ex1'
The last line of the rewrite log is as follows:
[perdir /var/www/domain/htdocs/test/] internal redirect with /app/index.php/content/ [INTERNAL REDIRECT]
How can I get this to rewrite to /app/index.php/content/?name=ex1 ?
EDIT
so using this as an .htacces in the docroot file works for the 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
Any help getting the bottom RewriteRule (that is currently commented out) to work would be appreciated.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的示例中,您提到了domain/test/,因此我将从 /test/*.html 重写为 /app/index.php/content/?name=
这应该可行。
In your example you mentioned domain/test/ so I'm going based of rewriting from /test/*.html to /app/index.php/content/?name=
That should work.
嗯,我突然想到:
这假设重写基础是 /
Uhm, off the top of my head:
This assumes that the rewrite base is /