【问题标题】:How to handle this URL?如何处理这个 URL?
【发布时间】:2015-04-16 14:44:23
【问题描述】:

我有 http://www.example.com/contact-us.php URL,它运行良好,但如果有人输入 http://www.example.com/contact-us.php/contact-us.php,它会显示 CSS 受到干扰的页面。

我们可以向用户显示此http://www.example.com/contact-us.php/contact-us.php URL 的页面未找到消息吗?如果此页面存在或不存在。

更新:

我的 .htacess 文件 - /public_html/.htaccess :

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*[^/])$ http://%{HTTP_HOST}/$1/ [L,R=301]

【问题讨论】:

  • 您的网站似乎受到.htaccess 设置的影响。请同时发布其内容。
  • @Raptor 整页内容?
  • .htaccess的内容
  • @Raptor 我在服务器上没有 .htacess 文件

标签: php url


【解决方案1】:

您可以在您的服务器上创建一个 htaccess 文件,并为所有不直接指向此类文件的 URL 强制使用斜杠(请检查是否为 mod_rewirte is enabled or not):

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    #Force Trailing slash
    RewriteRule ^((.*)[^/])$ $1/ [L,R=301]
</IfModule> 

【讨论】:

  • 我在我的 .htacess 文件上放了上面,但它不工作
  • @RakeshShetty 请使用 htaccess 文件的完整代码更新您的问题并提及其文件路径
  • @RakeshShetty 您拼错了 htaccess 文件。它应该是“.htaccess”。重命名并再次检查。
  • 这是一个有问题的错字,但在服务器上它是 .htaccess
  • @RakeshShetty 请在启用 mod_rewrite 后使用更新后的答案重试(如果尚未启用)
猜你喜欢
  • 1970-01-01
  • 2014-12-26
  • 2019-03-16
  • 2011-12-13
  • 2011-12-26
  • 2017-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多