【问题标题】:Redirect directory (but not subdirectories) to another directory将目录(但不是子目录)重定向到另一个目录
【发布时间】:2014-04-18 22:36:29
【问题描述】:

如何将目录重定向到站点的根目录?前提是:

  • 站点的根目录实际上不是域的根目录。例如:它应该重定向到“www.example.com/website”,而不是“www.example.com”

  • 不要重定向子文件夹。例如:它应该将“www.example.com/website/portfolio”重定向到“www.example.com/website”,但不应重定向“www.example.com/website/portfolio/project-name”。

这是一个 WordPress 网站,它已经在使用以下规则:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /website/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /website/index.php [L]
</IfModule>
# END WordPress

提前致谢!

【问题讨论】:

    标签: wordpress .htaccess mod-rewrite redirect subdirectory


    【解决方案1】:

    你可以这样做:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /website/
    
    RewriteRule ^portfolio/?$ /website/ [L,R]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /website/index.php [L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2019-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多