【发布时间】:2019-03-26 14:01:27
【问题描述】:
我在托管在 VPS 上的网站上使用微框架 Silex。
因此,站点文件位于 /site_name/public_html/ 文件夹中,但对于 Silex,站点必须指向 /site_name/public_html/web/ 文件夹。
在public_html 目录中,我有以下.htaccess 文件:
Options -Indexes -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Redirect to https & www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]
# Redirect incoming URLs to web folder
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
</IfModule>
并且,在/public_html/web/ 文件夹中,以下.htaccess:
<IfModule mod_rewrite.c>
# Redirect incoming URLs to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
现在,一切正常,但我的页面可以通过三种不同的模式访问:
-
example.com/page/(我想保留的那个) example.com/web/page/example.com/web/index.php/page/
我已使用元规范来避免重复内容,但我仍然希望最后两个选项不存在。
我想我在两个 .htaccess 文件中都有一些要更改的内容,但我找不到它是什么。
【问题讨论】:
标签: .htaccess redirect mod-rewrite url-rewriting silex