【问题标题】:htaccess remove file extension for domain and subdomains (eg. example.com and test.example.com)htaccess 删除域和子域的文件扩展名(例如 example.com 和 test.example.com)
【发布时间】:2013-08-18 10:07:43
【问题描述】:

我有一个根域 www.example.com 和一个子域 test.example.com。我正在尝试删除文件扩展名 - 到目前为止,我可以删除根域的文件扩展名,但不能删除子域 - 它会引发 404 not found 错误。下面是我在根文件夹中的 .htaccess 代码:

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

例如,我可以输入 www.example.com/page,它会显示 www.example.com/page.php,但如果我输入 test.example.com/some-page,它会返回 404 - 我需要输入 test.example.com/some-page.php 以显示页面。

我还想重定向所有 www。请求非 www。域名:

www.example.com -> example.com www.test.example.com -> test.example.com

【问题讨论】:

    标签: php apache .htaccess


    【解决方案1】:

    您需要在您的域上设置wildcard。如果未设置,您需要将 .htaccess 放在每个子域文件夹中。

    将“www”重写为非 www 地址的规则:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-02
      • 2019-01-03
      • 1970-01-01
      相关资源
      最近更新 更多