【问题标题】:Issue with URL RewriteRuleURL RewriteRule 的问题
【发布时间】:2012-03-10 02:49:56
【问题描述】:

我正在使用此RewriteRule ^page/([0-9]+)/ page.php?id=$1 将 URL http://example.com/page.php?id=00001 更改为 http://example.com/page/00001/,尽管任何图像或 CSS/JS/etc 页面不再正确链接。

EG:http://example.com/_img/image.jpg 变成http://example.com/page/00001/_img/image.jpg

有没有办法改变整个目录?例如,我试过这个:

RewriteRule ^page/([0-9]+)/(.*?) $2

但这没有用。感谢您的帮助!

编辑:
好的,这似乎有效,但只有其中一个有效,具体取决于哪个是第一个。

RewriteEngine on

RewriteRule ^page/([0-9]+)/(.*)$ $2
RewriteRule ^page/([0-9]+)/ page.php?id=$1

这样它会忽略第二个,所以http://example.com/page/00001/ 现在是http://example.com/index.php?id=00001 而不是http://example.com/page.php?id=00001
是否可以同时考虑第二个?

【问题讨论】:

标签: url mod-rewrite


【解决方案1】:

经过多次尝试,事实证明我错了。应该是这样的:

RewriteEngine on

RewriteRule ^page/([0-9]+)/$ page.php?id=$1
RewriteRule ^page/([0-9]+)/(.*) $2

这使得http://example.com/page/00001/ 实际上链接到http://example.com/page.php?id=00001,但其他任何东西——比如http://example.com/page/00001/_img/image.jpg 使用真实的URL,即http://example.com/_img/image.jpg

【讨论】:

    【解决方案2】:

    也许这样的事情会起作用:

    RewriteEngine On
    
    RewriteRule ^page/([0-9]+)/(.+)$ $2
    RewriteRule ^page/([0-9]+)/?$ /page.php?id=$1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多