我正在清理我的域的目录结构(我需要在根目录中设置根网址的内容!),需要一些见解关于如何正确使用RewriteRule。.htaccess:重定向根网址到子目录,但保留根网址
要义
我想使用domain.tld使用使用domain.tld /子目录/但仍显示为在URL 使用domain.tld。
我的.htaccess到目前为止
Options +FollowSymlinks
RewriteEngine On
#Force removal of wwww subdomain
RewriteBase/
RewriteCond %{HTTP_HOST} ^www.domain.tld
RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L]
#Trailing slash
RewriteRule ^/*(.+/)?([^.]*[^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
#Redirect root url to subdirectory
RedirectMatch 301 ^/subdirectory/$ http://domain.tld/
RewriteRule ^/$ /subdirectory/?$ [L]
的RedirectMatch的伟大工程。不幸的是,t似乎最后的RewriteRule 应该工作就够了,但事实并非如此。根目录中的旧内容设置仍然出现。
我在这里错过了什么?
更新:,我没有足够的经验与htaccess的/阿帕奇解决
简单的解决方法,以便能够解释为什么。
我:
RewriteRule ^/$ /subdirectory/?$ [L]
取出一个斜杠固定的一切:
RewriteRule ^$ /subdirectory/?$ [L]
所以现在我的问题是:这是为什么?