modrewrite RewriteRule问题

发布于 2024-09-02 22:39:20 字数 1327 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月隐月明月朦胧 2024-09-09 22:39:20

在您的示例中,您提到了domain/test/,因此我将从 /test/*.html 重写为 /app/index.php/content/?name=

RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*)\.html$ /app/index.php/content/?name=$1

这应该可行。

In your example you mentioned domain/test/ so I'm going based of rewriting from /test/*.html to /app/index.php/content/?name=

RewriteEngine On
RewriteBase /
RewriteRule ^test/(.*)\.html$ /app/index.php/content/?name=$1

That should work.

冷弦 2024-09-09 22:39:20

嗯,我突然想到:

RewriteCond %{REQUEST_URI} ^/app/(.*)\.html$
RewriteRule ^/app/(.*)\.html$ /app/index.php/content/?name=$1

这假设重写基础是 /

Uhm, off the top of my head:

RewriteCond %{REQUEST_URI} ^/app/(.*)\.html$
RewriteRule ^/app/(.*)\.html$ /app/index.php/content/?name=$1

This assumes that the rewrite base is /

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文