【问题标题】:htaccess — redirect to www and catch all index.phphtaccess — 重定向到 www 并捕获所有 index.php
【发布时间】:2015-05-13 23:27:07
【问题描述】:

我是 htaccess 的新手,所以提前道歉。 我正在尝试将所有非 www 重定向到 www。到现在为止还挺好。同时,我也在尝试捕获所有指向 index.php 的链接(未显示“index.php”)。

我尝试合并以下几行,但未能成功使 htaccess 正常工作:

 RewriteCond %{HTTP_HOST} !^www\.
 RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NC]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php?/$1 [QSA]

它将所有非 www 重定向到 www 并且不显示“index.php”。但我也想保留完整的网址。

例子:

example.com/subfolder 应该链接到 www.example.com/subfolder 但显示 index.php

感谢您的帮助!

【问题讨论】:

  • 我能否理解您希望在指向默认索引的所有 URL 后面加上 index.php。即www.example.com/subfolderwww.example.com/subfolder/index.php?

标签: .htaccess mod-rewrite redirect web


【解决方案1】:

我(希望)通过反复试验回答了我自己的问题。

RewriteCond %{HTTP_HOST} !^www.example.com$ [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA]

当然要开启 RewriteEngine

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 2019-08-12
    • 1970-01-01
    • 2017-01-12
    • 2022-01-16
    • 1970-01-01
    • 2012-03-08
    相关资源
    最近更新 更多