简体   繁体   English

.htaccess通配符子文件夹到另一个子文件夹

[英].htaccess wildcard subfolder to another subfolder

Here's my folder structure: 这是我的文件夹结构:

{root}/pages/page1/index.php {root}/pages/page2/index.php {root}/pages/page3/index.php

Here's what I'm trying to accomplish: 这是我要完成的工作:

When I go to {root}/page1 , it checks the /pages subdirectory to see if there is a matching folder name, then it loads that folder. 当我转到{root}/page1 ,它将检查/pages子目录以查看是否存在匹配的文件夹名称,然后它将加载该文件夹。 If not, it 404's. 如果不是,则为404。 I would want this set with a wildcard so I wouldn't have to add it manually. 我希望此集带有通配符,因此无需手动添加。

At the main root directory .htaccess file put the following code : 在主根目录.htaccess文件中,输入以下代码:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/pages/page1/
RewriteRule ^page1/(.*)$     /pages/page1/$1 [L]

If you want a code to work with all in pages directory change it to this : 如果要使代码与所有页面目录一起使用,请将其更改为:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/pages/(.*)/
RewriteRule ^(.*)/(.*)$     /pages/$1/$2 [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM