Apache 从任何子目录重定向到根目录
Apache redirect from any subdirectory to root
我想从
等任何子目录重定向用户
example.com/abc
example.com/xyz/abc
example.com/123/456/789
到根目录的内容,但我希望这个 link 保持这样,所以我可以用 JavaScript 阅读它。所以用户键入 example.com/xyz,按回车键,会出现根目录中的任何内容,但在地址字段中他仍然看到 example.com/xyz。
您可以在 DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# route to landing page
RewriteRule . / [L]
但是请记住,您正在创建重复的内容。
我还找到了另一个解决方案。
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource
我想从
等任何子目录重定向用户example.com/abc
example.com/xyz/abc
example.com/123/456/789
到根目录的内容,但我希望这个 link 保持这样,所以我可以用 JavaScript 阅读它。所以用户键入 example.com/xyz,按回车键,会出现根目录中的任何内容,但在地址字段中他仍然看到 example.com/xyz。
您可以在 DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# route to landing page
RewriteRule . / [L]
但是请记住,您正在创建重复的内容。
我还找到了另一个解决方案。
http://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource