首页 > 解决方案 > 如何将特定的无扩展端点重定向到另一个具有扩展名的端点

问题描述

我想重定向myapp.com/foomyapp.com/redirect.php

/foo 是不存在的端点

我有以下.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # This is not working
    RewriteRule ^foo /redirect.php [R=301,NC,L]

    # Enfore SSL - This works
    RewriteCond %{HTTP_HOST} ^(www\.)?myapp\.com$ [NC]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
</IfModule>

标签: php.htaccessubuntuapache2

解决方案


如果你在 foo 之后添加 $ 那么什么都会改变?

RewriteRule ^foo$ redirect.php [R=301,L]

或使用 RewriteBase

RewriteBase /
RewriteRule ^foo$ redirect.php [R=301,L]

推荐阅读