【问题标题】:apache redirect /url1/* to /url1/index.htmlapache 重定向 /url1/* 到 /url1/index.html
【发布时间】:2021-04-26 12:17:22
【问题描述】:

我将上下文 URL 更改为: domain.name/url1domain.name/url2

我想对来自

的所有 URL 进行 301 重定向

domain.name/url1/* 到静态文件domain.name/url2/moved.html 并显示静态维护页面

重写规则不应考虑除 domain.name/url1/* 之外的任何其他 URL 用于此重定向

url1url2是apache目录下的子文件夹/var/www/home/

apache的配置是:

Listen 9082
<VirtualHost *:9082>

ServerName domain.name

DocumentRoot "/var/www/home"

<Directory />
  Require all denied
</Directory>

<Directory "/var/www/home">
  Require all granted
  RewriteEngine on
  AllowOverride all

</Directory>

<IfModule dir_module>
  DirectoryIndex index.html index.htm index.php
</IfModule>

</VirtualHost>

【问题讨论】:

    标签: linux apache mod-rewrite url-rewriting virtualhost


    【解决方案1】:

    您可以在url1/.htaccess 中尝试此代码:

    DirectoryIndex index.html
    RewriteEngine On
    
    RewriteRule ^index\.html$ - [NC,L]
    
    RewriteRule . /url1/ [L,R=301]
    

    【讨论】:

    • 我编辑了问题以显示 apache 配置。因为您的解决方案也会影响 url2 子文件夹
    • your solution would impact url2 subfolder also : 你是怎么得出这个结论的? RewriteRule ^uri1/. uri1/ [NC,L] 只会影响url1/
    • 我尝试了您的解决方案,当我检查domain.name/url1/iy8yaigsdfg 时,它显示Not Found,当我检查domain.name/url2/ 时,它正在重定向到domain.name/url1
    • 复制/粘贴有问题的完整 .htaccess,您必须清除浏览器缓存
    • 我更新了。在url1/.htaccess按原样使用此代码
    猜你喜欢
    • 2015-07-26
    • 2020-07-09
    • 1970-01-01
    • 2012-03-12
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多