Apache - 仅将域URL重定向到子页面

时间:2014-01-30 12:55:42

标签: apache .htaccess redirect

我有一个共享主机Apache服务器,我正在尝试将访问主域URL的访问者发送到特定页面,并更换URL并重定向:

example.com
example.com/

example.com/subdirectory/page.html

只应重定向纯域URL,而不是:

example.com/page.html
example.com/otherdirectory
example.com/otherdirectory/
example.com/subdirectory
example.com/subdirectory/
example.com/subdirectory/otherpage.html
example.com/subdirectory/otherdirectory
example.com/subdirectory/otherdirectory/
example.com/subdirectory/otherdirectory/page.html

如果可能有其他方法,我不确定此服务器上是否允许使用RewriteEngine。

我想到的原始方法是使用DirectoryIndex将访问者发送到example.com/index.php - 并在该文件中进行PHP重定向到我想要的地方。但是我不确定这是否会给一些访问者带来明显的昙花一现,或者Google对此感觉如何。

我在Stack Overflow上找到了这类问题的其他实例,但是答案在某些方面对我失败了。由于行为不直观,因此建议在发布之前进行测试。

由于

1 个答案:

答案 0 :(得分:1)

如果未启用mod_rewrite,您可以在mod_alias中使用基于DocumentRoot/.htaccess的规则:

RedirectMatch 303 ^/?$ /subdirectory/page.html

更新:等效的mod_rewrite规则:

RewriteEngine On

RewriteRule ^/?$ /subdirectory/page.html [L,R=303]
相关问题