我在这样的结构中有多个文件/文件夹:
2019年/
2018年/
..。
2000年/夏季/
2000年/冬季/
index.php
.htaccess
如果用户输入domain.com/2019/他应该被重定向到主根目录中的index.php。如果用户输入domain.com/2018/.
我的问题是:是否需要在每个文件夹中进行一次htaccess才能使其发生?或者,我是否可以向主.htaccess中添加一些东西,从而自动将此行为添加到域上没有index.php文件的每个文件夹中?
发布于 2019-05-23 14:15:20
您只需在您的.htaccess文件中添加这一行
# Turn rewriting on
Options +FollowSymLinks
RewriteEngine On
# Redirect requests to index.php
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !.*\.png$ [NC]
RewriteCond %{REQUEST_URI} !.*\.jpg$ [NC]
RewriteCond %{REQUEST_URI} !.*\.css$ [NC]
RewriteCond %{REQUEST_URI} !.*\.gif$ [NC]
RewriteCond %{REQUEST_URI} !.*\.js$ [NC]
RewriteRule .* /index.phphttps://stackoverflow.com/questions/56276874
复制相似问题