重定向错误和浏览器显示太多

时间:2016-09-22 11:12:26

标签: apache .htaccess redirect mod-rewrite document-root

With Reference htaccess RewriteRule redirecting to parent directory?

感谢Francesco Casula,您的回答非常有用,应用程序现在从一个文档根重定向到另一个。我面临无限重定向问题。

我有以下不同版本的存储库。

  1. /var/www/portal/version/1.1.1/public/与(api.somedomain.com)绑定
  2. /var/www/portal/version/1.1.2/public /
  3. /var/www/portal/version/1.1.3/public /
  4. /var/www/portal/version/1.1.4/public /
  5. 我想按照以下顺序(按版本)执行api

    api.somedomain.com/qr ---> /var/www/portal/version/1.1.1/public /

    api.somedomain.com/v2/qr ---> /var/www/portal/version/1.1.2/public /

    api.somedomain.com/v3/qr ---> /var/www/portal/version/1.1.3/public /

    api.somedomain.com/v4/qr ---> /var/www/portal/version/1.1.4/public /

    我的httpd.conf是

     AliasMatch ^/v2/(.*)$ "/var/www/portal/version/1.1.2/public/"
     <Directory "/var/www/portal/version/1.1.2/public">
       Options Indexes FollowSymLinks MultiViews
       AllowOverride all
       Order allow,deny
       Allow from all
     </Directory>
    .
    .
    AliasMatch ^/v4/(.*)$ "/var/www/portal/version/1.1.4/public/"
     <Directory "/var/www/portal/version/1.1.4/public">
       Options Indexes FollowSymLinks MultiViews
       AllowOverride all
       Order allow,deny
       Allow from all
     </Directory>
    
    /var/www/portal/version/1.1.4/public/中的

    和.htaccess包含

    <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
        RewriteEngine On
        # Redirect Trailing Slashes...
        RewriteRule ^(.*)/$ /$1 [L,R=301]
    
        RewriteCond %{REQUEST_URI} ^/v2/(.*)$
        RewriteRule ^(.*)$ v2/index.php [QSA,L] # p2 is the symlink name!
    
        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    
    </IfModule>
    

    当我点击 https://api.somedomain.com/v2/invitebysms

    我收到太多重定向错误和浏览器显示

    https://api.somedomain.com/v2/invitebysms/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/

1 个答案:

答案 0 :(得分:0)

我认为您的目标是:

Alias /v4/ /var/www/portal/version/1.1.4/public/
<Directory /var/www/portal/version/1.1.4/public/>
  Require all granted
  FallbackResource /v4/index.php
</Directory>

据我了解你要完成的任务,上面的,在你的服务器配置中(完全删除.htaccess文件)会做你想要的。 (对v2,v3等重复。)

我假设您至少运行2.2.16或更高版本,最好是2.4。如果没有,请告诉我,我们会再试一次。