【问题标题】:mod_rewrite for specific url onlymod_rewrite 仅用于特定的 url
【发布时间】:2013-05-22 07:42:43
【问题描述】:

我喜欢用不同的方式重写一个 url。我的意思是我想知道如何使用 mod_rewrite 以便我可以执行以下操作:

1- 将 .php 转换为 html 以获得特定的 url 即:从www.mydomain.com/news.phpwww.mydomain.com/news.html

我发现了一些有趣的代码,但不确定哪一个可以正常工作...

我发现的一些东西:

RewriteEngine on
RewriteRule ^(\d+)/(\w+).html$ index.php?id=$1&title=$2

2- 将该 news.php 文件的任何子 url 转换为

news.php?do=news&id=24455

所以主题或线程显示像这样没有斜线/

我发现第二个问题很困难,但肯定有解决方案。

知道如何为特定网址完成这两个问题,就像我上面所说的那样......!!

谢谢

【问题讨论】:

  • 例如,news.php 是主文件夹 'url',所以后面的任何内容都是子 url,例如 --> news/article1.php 或有时是 news.php?art2432... 等等......也许我没有把它放在正确的名字,但肯定每个人都能得到它:)
  • news/article1.phpnews/article1.html?您希望哪一个在用户的浏览器地址栏中可见? “等等”——它不是那样工作的。您需要为 url 定义一个 exact 模板。
  • 我猜你是对的。我定义了确切的模板。好的,如果在 news.php 中添加线程怎么样 ---> 不能这样 news.php?do=news&id=24455
  • 应该重写的原始 url 是什么? /news/24455.html?
  • 是的,完全正确。 /news/24455.html

标签: php html mod-rewrite url-rewriting


【解决方案1】:

将 .php 转换为 html 以获得特定的 url,即:从 www.mydomain.com/news.php 到 www.mydomain.com/news.html

RewriteRule ^news\.html$ /news.php

猜第二个(假设你想重写/news/foo.html urls):

RewriteRule ^news/(.*)\.html$ /news.php?id=$1

【讨论】:

  • 我会试试看。谢谢
  • 上面的代码很好地完成了将 .php 重写为 .html 的工作,非常感谢。现在唯一的事情就是在尝试使用 .html。
  • 顺便说一句,以前使用 .php url,当我添加任何线程时,我会得到 news.php?c=111 originally...
  • @Digital site:我不知道你在说什么:-S
  • 没关系,我认为您的解决方案可以。非常感谢,伙计
猜你喜欢
  • 2020-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多