如预期的mod_rewrite不工作 [英] Mod_rewrite isn't working as intended

查看:248
本文介绍了如预期的mod_rewrite不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个特定的结构化的URL重写到另一个结构。

I'm trying to rewrite a specific structured url to another structure.

原始URL是

http://www.mywebsite.com/FF_Supersneaker_Black_Metallica_p/155-157.htm

和我想它重写

http://www.mywebsite.com/FF_Supersneaker_Black_Metallica.html

除去基本上_p / 155-157.htm和附加的.html

essentially removing "_p/155-157.htm" and appending .html

我使用要做到这一点htaccess文件是

The htaccess file I am using to do this is

<IfModule mod_rewrite.c>  
    RewriteEngine On    
    RewriteRule /(.*)/(.*)_p/[^/]*.htm$ /$1$2.html
</IfModule>

但它似乎是失败的,这是重写日志将页面时,我得到。

But it seems to be failing, Here is the rewrite log I get when going to the page.

255.255.255.255 - - [25/Apr/2012:12:34:43 --0400] [www.mywebsite.com/sid#9b25ed8][rid#9e33c28/initial] (3) [perdir /var/www/test/] strip per-dir prefix: /var/www/test/FF_Supersneaker_Black_Metallica_p/155-157.htm -> FF_Supersneaker_Black_Metallica_p/155-157.htm
255.255.255.255 - - [25/Apr/2012:12:34:43 --0400] [www.mywebsite.com/sid#9b25ed8][rid#9e33c28/initial] (3) [perdir /var/www/test/] applying pattern '/(.*)/(.*)_p/[^/]*.htm$' to uri 'FF_Supersneaker_Black_Metallica_p/155-157.htm'
255.255.255.255 - - [25/Apr/2012:12:34:43 --0400] [www.mywebsite.com/sid#9b25ed8][rid#9e33c28/initial] (1) [perdir /var/www/test/] pass through /var/www/test/FF_Supersneaker_Black_Metallica_p/155-157.htm

我相信这看起来似乎是错了我的规则,但我不知道是什么。如果任何人都可以给我一些想法,我AP preciate它。

I believe it seems like something is wrong with my rule, but I'm not sure what. If anyone can give me some thoughts, I'd appreciate it.

感谢您的任何帮助。

推荐答案

首先,看看这个:

strip per-dir prefix: /var/www/test/FF_Supersneaker_Black_Metallica_p/155-157.htm -> FF_Supersneaker_Black_Metallica_p/155-157.htm

你对抗实际上是 FF_Supersneaker_Black_Metallica_p / 155-157.htm 因为你是一个目录上下文中运行(从匹配的路径的.htaccess 文件)。所以它不会匹配任何开头 / ...

That path you're matching against is actually FF_Supersneaker_Black_Metallica_p/155-157.htm because you're running inside a directory context (from a .htaccess file). So it's not going to match anything starting with /...

这意味着你真正想要的只是...

That suggests that what you really want is simply...

RewriteRule (.*)_p/[^/]*.htm$ /$1.html

...如果你想要的结果是:

...if you want the result to be:

FF_Supersneaker_Black_Metallica.html

这篇关于如预期的mod_rewrite不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆