我正在尝试基于特定关键字调度多个目录中的所有流量。
我有以下目录结构:
dotcom/
dotcom/directory1/ (with subdirs)
dotcom/directory2/ (with subdirs)
dotcom/directory3/ (with subdirs)
我在dotcom中有一个.htaccess文件,我想将每个目录后面的所有内容重定向到每个目录中的索引文件。
示例:
dotcom/directory1/anything/blabla to dotcom/directory1/index.php
dotcom/directory2/anything/blabla to dotcom/directory2/index.php
dotcom/anythingNotExisting to dotcom/index.php
任何不在现有目录中的内容都应该重定向到dotcom/index.php
我尝试了以下网络:
RewriteEngine On
RewriteCond %{ENV:HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这捕获了所有
但当我尝试添加以下条件时,我得到了404:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/directory1/(.*)$ directory1/index.php?path=$1 [NC,L,QSA]
有了这个,如果我试图访问dotcom/directory1/bblabla,我有一个404,而如果我访问dotcom/directory1/,它会转到右侧的index.php
我试过使用完整路径的dotcom/directory1/,但没有帮助。
您可以在dotcom/.htaccess
:中使用这些规则
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
# ignore all rules below this for real files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# for URIs starting with know directory paths
RewriteRule ^(directory1|directory2)/(.*)$ $1/index.php?path=$2 [NC,L,QSA]
# everything else
RewriteRule .+ index.php?path=$0 [L,QSA]
我发现了一些适用于以下内容的东西:
RewriteEngine ON
RewriteCond HTTPS off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^directory1/(.*)$ /dotcom/directory1/index.php?path=$1 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^directory2/(.*)$ /dotcom/directory2/index.php?path=$1 [NC,L,QSA]
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dotcom/index.php?path=$1 [NC,L,QSA]
通过这种方式,我捕获了/directoryX/中的所有内容,并将其重定向到目录的根目录,其他内容都转到dotcom