【问题标题】:How to write .htaccess file code to change old url to new url如何编写 .htaccess 文件代码以将旧网址更改为新网址
【发布时间】:2016-09-28 05:22:21
【问题描述】:

我想使用 .htaccess 重写我的网址。我的旧网址是http://gametesting.in/infocomstudios/gamedetails.php?id=2,我需要将其更改为以下http://gametesting.in/infocomstudios/demopage.html。我的 .htaccess 中使用了什么代码。我尝试使用以下代码:

    RewriteCond %{QUERY_STRING} ^id=2$
RewriteRule ^gamedetails\.php demopage.html [L,R]

但我得到一个错误:

请求的 URL /home/gamet/public_html/infocomstudios/demopage.html 在这服务器上没找到。此外,404 Not Found 错误是 尝试使用 ErrorDocument 处理 请求。

我的新网址变成:http://gametesting.in/home/gamet/public_html/infocomstudios/demopage.html?id=2

请帮我解决这个问题。

【问题讨论】:

  • 这是一个标准的 404 错误。服务器找不到新页面。可能与 ?id=2 在 html 文件上不可接受有关。
  • @Linkan 感谢您的评论。但实际上我想重写我的 url。所以不需要创建那个 html 文件
  • 规则的编写方式是,您将访问 gamedetails.php?id=2 的人发送到 demopage.html,它必须存在才能正常工作。

标签: php .htaccess codeigniter url


【解决方案1】:

我刚刚调整了你的规则来保存路径和查询字符串:

RewriteCond %{QUERY_STRING} ^id=2$
RewriteRule ^(.*)gamedetails\.php(.*) $1demopage.html$2 [L,R]

在线测试here

【讨论】:

  • Thanku @copynpaste ..使用您的代码时出现同样的错误。此问题的任何其他解决方案?我是第一次在 .htaccess datz y
  • 啊,真的没有读到那个错误。您确定该文件存在于该位置吗? ServerUser(例如 Apache 上的 www-data)可以访问它吗?
  • 实际上我没有名称为 demopage.html 的页面,当我调用它时 gametesting.in/infocomstudios/gamedetails.php?id=2 然后只显示以下网址 @ 987654323@
  • 您只想在 url 中使用 demopage.html 作为 gamedetailts.php?id=2 的替代品,但又想保留内容?
  • 是的..但我的原始网址是 gametesting.in/infocomstudios/gamedetails.php?id=2 我想将其替换为 gametesting.in/ infocomstudios/demopage.html
【解决方案2】:

试试这个我还没有测试过请告诉如果告诉如果错误。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^infocomstudios/demopage.html$ infocom/gamedetails.php?id=2 [L]

【讨论】:

    猜你喜欢
    • 2021-04-04
    • 2016-11-22
    • 2016-11-03
    • 2016-07-17
    • 2011-05-23
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 2017-05-10
    相关资源
    最近更新 更多