.htaccess htaccess将所有文件重定向到index.php,而不是特定的子目录
我有一个站点,其中所有请求都应该转到index.php,除了特定子目录中的请求,这些请求应该转到subdirectory/index.php 我希望将目录路径转换为查询字符串,以便在子目录索引页中使用 我真的对htaccess文件知之甚少,我确信这个问题已经被回答了一百次,但我不知道要搜索什么才能得到答案 所以-这就是我希望在这种情况下发生的事情.htaccess htaccess将所有文件重定向到index.php,而不是特定的子目录,.htaccess,.htaccess,我有一个站点,其中所有请求都应该转到index.php,除了特定子目录中的请求,这些请求应该转到subdirectory/index.php 我希望将目录路径转换为查询字符串,以便在子目录索引页中使用 我真的对htaccess文件知之甚少,我确信这个问题已经被回答了一百次,但我不知道要搜索什么才能得到答案 所以-这就是我希望在这种情况下发生的事情 RULE 1 www.example.com/anything_or_nothing <goes to> /index.php www.e
RULE 1
www.example.com/anything_or_nothing <goes to> /index.php
www.example.com/anything/anything_else <goes to> /index.php
RULE 2
www.example.com/subdirectory/ <goes to> /subdirectory/index.php
RULE 3
www.example.com/subdirectory/some_other_directory/ <goes to> /subdirectory/index.php?a=some_other_directory
我无法使.htaccess文件在子目录中工作,因此我希望所有规则都在根.htaccess文件中
我从其他网站拼凑了这个.htaccess,所以我为自己的无知道歉,但我不知道该去哪里
先谢谢你
其他信息>>>>>>>>>
我尝试过的其他事情
这个
停止所有规则的工作
这:
似乎与原始示例一样。正如您自己回答的那样,第二条规则是不必要的
# Don't rewrite if file already exists to prevent rewriting images, scripts etc
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
# Rewrite sub/anything to sub/index.php?a=anything
RewriteRule ^sub/([^/]+)$ sub/index.php?a=$1 [L,NC]
# Fallback all unknown requests to index.php
RewriteRule .* index.php [L,NC]
警告:当您将不存在的文件重写到index.php时,此方法将完全隐藏所有自然404错误。您是否尝试更改重写规则的顺序?例如,将其反转。感谢您的回复-我已经尝试过这个-在上面的帖子中编辑。
RewriteRule ^/sub/([^/\.]+)/?$ /sub/index.php?a=$1 [L,NC]
RewriteRule ^/sub.*$ /sub/index.php
RewriteRule ^.*$ ./index.php
RewriteRule ^.*$ ./index.php
RewriteRule ^/sub/([^/\.]+)/?$ /sub/index.php?a=$1 [L,NC]
RewriteRule ^/sub.*$ /sub/index.php
# Don't rewrite if file already exists to prevent rewriting images, scripts etc
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
# Rewrite sub/anything to sub/index.php?a=anything
RewriteRule ^sub/([^/]+)$ sub/index.php?a=$1 [L,NC]
# Fallback all unknown requests to index.php
RewriteRule .* index.php [L,NC]