【问题标题】:htaccess index.php redirect to roothtaccess index.php 重定向到根目录
【发布时间】:2017-01-12 23:40:37
【问题描述】:

好的,我有几个关于 htaccess 的问题。

首先我希望website/index.php 成为website/,即使最后有人输入index.php

其次,我想删除.php,即使您输入并在末尾添加/ website/about-us.phpwebsite/about-us/

我添加了这个以删除最后的扩展:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

除了不能 100% 确定如何添加 /,而且我发现将 index.php 更改为 url 根的所有内容都对我不起作用。

【问题讨论】:

    标签: php .htaccess url redirect


    【解决方案1】:

    试试这个

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]+)/$ $1.php
    RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule (.*)$ /$1/ [R=301,L]
    

    【讨论】:

      【解决方案2】:

      试试这个规则,

      DirectoryIndex index.php
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} -f
      RewriteRule ^index.php$ www.{HTTP_HOST}/ [R=301]
      RewriteCond %{REQUEST_FILENAME}.php -f
      RewriteRule ^([^\.]+)$ $1.php [NC,L]
      

      【讨论】:

        猜你喜欢
        • 2012-04-27
        • 2013-03-06
        • 2016-11-22
        • 1970-01-01
        • 2013-04-10
        • 1970-01-01
        • 2016-01-21
        • 1970-01-01
        • 2014-10-23
        相关资源
        最近更新 更多