【问题标题】:How to render same page with different url using htaccess如何使用 htaccess 渲染具有不同 url 的同一页面
【发布时间】:2016-04-30 14:07:47
【问题描述】:

我有新域,现在我想将所有 url 呈现到主页。

例如。

abc.com/abc
abc.com/abc/xyz
abc.com/abc/xyz/123
abc.com/abc/abc/xyz/123/so_on 

url 也将只显示当前主页(index.html(或 .php))而不是

“未找到,在此服务器上未找到请求的 URL /index.php。”

如何使用 htaccess 做到这一点?

【问题讨论】:

  • 首先,我缺少 http 服务器。这可能不是绝对必要的(我不知道答案),但可能需要回答这个问题。其次,关于“Also URL will show”,您的意思是您希望将所有 URI 转发到 index.html 还是目前的情况?

标签: .htaccess url-rewriting


【解决方案1】:

您可以在 .htaccess 中使用重写规则

RewriteEngine On
RewriteRule ^.*$ index.php [NC,L]

这会将所有请求发送到 index.php 文件(或者您可以将其更改为 index.htm 等)

【讨论】:

    【解决方案2】:

    你也可以绕过css/js等静态文件:

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-10
      • 2023-03-03
      相关资源
      最近更新 更多