【问题标题】:Apache Rewrite issue with url with more than 1 slash带有超过 1 个斜杠的 url 的 Apache 重写问题
【发布时间】:2013-12-09 16:36:04
【问题描述】:

问题基本上是这样的:

我有一个网址:site.com?go=1&do=2&action3&id=4

如果我使用这样的重写方法:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([A-Za-z0-9_-]+)$ /index.php?go=$1
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ /index.php?go=$1&do=$2
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ /index.php?go=$1&do=$2&action=$3
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ /index.php?go=$1&do=$2&action=$3&id=$4

它只适用于第一个斜线。例如:

site.com/go -> 这行得通但是这个site.com/go/do 破坏了整个页面,它找不到css,imgs,什么都没有!我该如何解决?

谢谢!

【问题讨论】:

    标签: php html apache .htaccess rewrite


    【解决方案1】:

    你需要在你的头上设置<base>标签,并将你的域名放在href中

    <head>
    <base href="http://www.sample.com/">
    </head>
    

    【讨论】:

    • 谢谢!这解决了我的问题,我必须等待 7 分钟才能接受您的回答 =S
    【解决方案2】:

    根据您的网址结构,您可能需要确保您的网址转义了反向引用。查看https://httpd.apache.org/docs/trunk/rewrite/flags.html

    【讨论】:

      猜你喜欢
      • 2019-07-18
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多