doudi4621 2016-08-02 09:25 采纳率: 0%
浏览 95
已采纳

WordPress项目旁边的Laravel项目(在public_html文件夹中)

I have a Laravel project in my public_html folder. The domain is for example domain.com My .htaccess file (in public_html folder) is like this:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

There are the following routes:

  • api/licenseplate
  • api/calendar
  • auth/login
  • admin/settings
  • admin/appointments
  • appointment
  • ...

So an example of a URL is http://domain.com/appointment.

Now I would like to have a wordpress website on domain.com. So when you go to domain.com you see the wordpress website. But I also want to have the urls like /appointment of my laravel project.

What's the easiest and cleanest way to do this?

  • 写回答

3条回答 默认 最新

  • dongxu7408 2016-08-05 07:50
    关注

    You can create symlink to Wordpress public directory in Laravel folder. For example, wp:

    /var
         /www
             /laravel
                 /public
                     /wp #(symlink to -> /var/www/wordpress/public_html)
                     index.php
                     .htaccess
             /wordpress
                 /public_html
                     index.php
                     .htaccess
    

    And describe Laravel routes in .htaccess. Example of code of /var/www/laravel/public/.htaccess:

    <IfModule mod_rewrite.c>
        <IfModule mod_negotiation.c>
            Options -MultiViews
        </IfModule>
    
        RewriteEngine On
    
        RewriteCond %{ENV:REDIRECT_FINISH} .
        RewriteRule ^ - [L]
    
        # Laravel
    
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteCond %{REQUEST_FILENAME} !.*\.php$
        RewriteRule ^(.*)$ $1 [E=FINISH:1,L]
    
        RewriteCond %{REQUEST_URI} ^/(api/licenseplate)(\?.*|$) [OR]
        RewriteCond %{REQUEST_URI} ^/(api/calendar)(\?.*|$) [OR]
        RewriteCond %{REQUEST_URI} ^/(admin/settings)(\?.*|$) [OR]
        RewriteCond %{REQUEST_URI} ^/(admin/appointments)(\?.*|$) [OR]
        RewriteCond %{REQUEST_URI} ^/(appointment)(\?.*|$) [OR]
        RewriteCond %{REQUEST_URI} ^/(auth/login)(\?.*|$)
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php [E=FINISH:1,L]
    
        # Wordpress
    
        RewriteCond %{REQUEST_URI} !^/wp
        RewriteRule ^(.*)$ /wp/$1 [E=FINISH:1,L]
    
    </IfModule>
    

    Code of /var/www/wordpress/public_html/.htaccess (just copy of your wordpress .htaccess):

    # BEGIN WordPress
    
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助