【问题标题】:URL rewriting not working on wamp serverURL重写在wamp服务器上不起作用
【发布时间】:2018-04-13 07:13:54
【问题描述】:

您好,我正在尝试练习 url 重写。我在路径中写入了 .htaccess 文件:C:\wamp64\www\RewriteUrl。在同一位置,我有文件 pet_care_info_01_02_2008.php 。我的重写规则是:

   RewriteEngine On    # Turn on the rewriting engine
   RewriteRule    ^pet-care/?$    pet_care_info_01_02_2008.php    [NC,L]    

所以我想将http://localhost/RewriteUrl/pet_care_info_01_02_2008.php 更改为http://localhost/RewriteUrl/pet-care.php。但目前它给了我整个路径而不是重写它。有什么想法吗?

【问题讨论】:

标签: php .htaccess url-rewriting wamp


【解决方案1】:

尝试:

RewriteEngine On    # Turn on the rewriting engine

# To externally redirect pet_care_info_ to pet_care.php
RewriteCond %{THE_REQUEST} /pet_care_info_ [NC]
RewriteRule ^ /RewriteUrl/pet_care\.php [R=301,L]

RewriteRule    ^pet_care\.php$    pet_care_info_01_02_2008.php    [NC,L]    

因为这就是你解释它的方式......
并尝试/RewriteUrl/pet_care.php

【讨论】:

  • 在此服务器上找不到请求的 URL /RewriteUrl/pet_care.php。如果我像你说的那样改变我的规则,它会给我这个。我希望 php 页面从 localhost 更改为 pet_care.php,但事实并非如此。它打开带有 URL localhost/RewriteUrl/pet_care_info_01_02_2008.php 的普通页面
  • 你的问题是pet-care !!!不是pet_care。我现在在我的回答中改变了这一点。
  • 是的,现在它可以工作了,但是我的原始网址 localhost/RewriteUrl/pet_care_info_01_02_2008.php 可以自动显示为 pet-care.php。因为现在我可以使用两个网址访问。?
  • 我在回答中添加了这一点
  • 非常感谢它的工作原理。您能否推荐任何链接来了解 url 重写规则。谢谢
猜你喜欢
  • 2015-04-01
  • 2014-01-11
  • 2018-06-15
  • 1970-01-01
  • 2016-10-31
  • 1970-01-01
  • 1970-01-01
  • 2015-07-08
  • 1970-01-01
相关资源
最近更新 更多