Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zidance's avatar

How to use dynamic url path for subfolder?

I have two project folder, e.g. blog1 and blog2.

I am doing it as sub folder instead of sub domain.

blog1 folder consists of laravel project. Inside blog2 folder, there's is a folder name main which consist of laravel project.

this is my htaccess for blog1

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
    RewriteRule ^(.*)$ blog1/public/ [L]
    RewriteRule ^cloud/(.*)$ https://website.com/cloud/ [NC,R=301,L]
</IfModule>

Every time access too blog1 is simple, just https://website.com/login

Every time i want to access blog2 project, this is the link looks like https://website.com/blog2/login

htaccess inside blog2

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

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

How can i make the link looks like https://website.com/blog2/ or https://website.com/blog2-sg/ or https://website.com/blog2-uk/?

Is that possible to make it?

Can anyone can help me with explanation on this if doable? Thanks.

0 likes
2 replies
Wraith's avatar

You have 2 projects in two folders. blog1 with your htaccess and blog2 with other htaccess. You should have set virtual host with domain like website.com going to directory /var/www/blog1 right ? So when u type website.com/blog2 system will redirect u to documentRoot website.com -> blog1 and doesn't matter what u have in blog2 dir and htacces.

You can create subdomain in vhost to reirect if u type blog1.website.com or website.com/blog1 or you can set htacces in blog1 and when someone type website.com/blog2 redirect to other folder blog2

without subdomain

RewriteCond %{HTTP_HOST} ^[^.]+.[^.]+$ RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

with subdomain

RewriteCond %{HTTP_HOST} ^www.([^.]+.[^.]+.[^.]+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

zidance's avatar

This is my htaccess in /var/www/html

RewriteRule ^(.*)$ blog1/public/ [L]
RewriteRule ^blog2(.*)$ blog2/laravel/public/ [L]

This return me 404 not found. But if i am writing in this way

RewriteRule ^blog2(.*)$ blog2/laravel/public/ [L]
RewriteRule ^(.*)$ blog1/public/ [L]

It works with https://website.com/blog2 and also https://website.com/blog2-uk. If i am using the first one, it only will works with https://website.com/blog2.

But what's wrong for the first one? I'm afraid will affect the blog1 project if i am changing the sequence. Any solution?

Please or to participate in this conversation.