【问题标题】:Url rewriting with parameters带参数的 URL 重写
【发布时间】:2012-11-08 19:58:32
【问题描述】:

我是 url 重写的菜鸟,我真的需要帮助来解决这个问题:

我有这个 url:section/news.php?url=section/news/27-how_to_make_rewrite.html 我想用 url 参数访问这个新闻,链接是:section/news/27-how_to_make_rewrite.html

.htacess 文件在根目录中,我有一个名为 section 的文件夹,在这个文件夹中我有 news 文件夹

这对我不起作用。

我有:

重写引擎开启 RewriteBase /section/ RewriteRule news/^([a-zA-Z0-9-+/]+)/$ news/news.php?url=$1

我该怎么做?

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    我没有将它与子文件夹一起使用,但我会尝试这样的。

    RewriteRule ^news/([^/\.]+)/?$ news/news.php?url=section/news/$1 [L]
    

    编辑

    试试这个方法:

    RewriteRule ^section/news/([^/.]+)/?$ news.php?url=section/news/$1 [L]
    

    您通常只想将变化的内容放入变量中。 section/news/ 总是被使用,所以你应该把它放在替换之外。

    【讨论】:

    • 我试过这个没有运气:RewriteRule ^([^/.]+)/?$ news/news.php?url=$1 我不认为我必须把文件夹放在 url就像你做的那样,因为路径已经在 url 参数中。
    【解决方案2】:

    如果你想重写 的 URI 看起来像:section/news.php?url=section/news/27-how_to_make_rewrite.html

    那么你的目标中的“新闻”太多了。您还需要修复正则表达式模式以匹配 27-how_to_make_rewrite.html 之类的内容。

    你想要这样的东西:

    RewriteEngine on
    RewriteBase /section/
    RewriteRule news/(.+)/?$ news/news.php?url=section/news/$1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 2013-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多