网站内部文件夹访问重定向到 index.php
website internal folder access redirect to index.php
我需要重定向到所请求目录的 index.php。我该怎么做?
js/
module/
lib/
data/
source/
theme/
示例:
http://www.example.com/folder/
应该这样重定向
http://www.example.com/index.php
你可以通过.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^js/(.*)$ / [R=301,NC,L]
但我更愿意在所有文件夹中保留一个 index.php
文件并重定向到根文件夹 index.php
,因为它还会重定向对现有文件的查询,例如图像,javascript 文件或样式表文件。
I need to redirect to index.php of whichever directory is requested. how do i do that ?
你的意思是这样的?
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/ -d
RewriteRule ^(.+)/[^/]*$ //index.php [L]
因此,如果您请求 /js/something
,您将被路由到 /js/index.php
,或者如果您请求 /module/something
,您将被路由到 /module/index.php
。
编辑
尝试
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/ -d
RewriteRule ^(.+)/ /index.php [L]
如果您想重定向浏览器,请将标记更改为 [L,R]
。
我需要重定向到所请求目录的 index.php。我该怎么做?
js/
module/
lib/
data/
source/
theme/
示例:
http://www.example.com/folder/
应该这样重定向
http://www.example.com/index.php
你可以通过.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^js/(.*)$ / [R=301,NC,L]
但我更愿意在所有文件夹中保留一个 index.php
文件并重定向到根文件夹 index.php
,因为它还会重定向对现有文件的查询,例如图像,javascript 文件或样式表文件。
I need to redirect to index.php of whichever directory is requested. how do i do that ?
你的意思是这样的?
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/ -d
RewriteRule ^(.+)/[^/]*$ //index.php [L]
因此,如果您请求 /js/something
,您将被路由到 /js/index.php
,或者如果您请求 /module/something
,您将被路由到 /module/index.php
。
编辑
尝试
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/ -d
RewriteRule ^(.+)/ /index.php [L]
如果您想重定向浏览器,请将标记更改为 [L,R]
。