douweinu8562 2015-06-16 09:11
浏览 105
已采纳

连接两个.htaccess文件

On my site is currently running wordpress so my .htaccess looks like this:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

But I need to test other(laravel) application there. If I replace .htaccess with this:

RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

my laravel app works. Is there any way how to be able to keep working both apps? Specifically it would be good if second app runs just on some alias e.g. www.mysite.com/secreturl. I tried to combine it like so:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


RewriteRule ^secret(.*)$ public/$1 [L]

But I couldn't achieve anything. Thanks.

  • 写回答

1条回答 默认 最新

  • dth2331 2015-06-16 09:24
    关注

    You can't have both apps in the same directory, because they would both need index.php as the application entry point and that creates conflicts (also Laravel's public directory shouldn't be inside the document root, it should be the document root).

    You should serve the Laravel application (if that's of secondary importance) using a virtual host either in a subdirectory or a subdomain. Here's an example using a subdomain:

    <VirtualHost *:80>
        ServerName laravelapp.example.com
        DocumentRoot "/path/to/larvel/app/public"
    
        <Directory "/path/to/larvel/app/public">
            AllowOverride all
        </Directory>
    </VirtualHost>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?