Jump to content

Apache rewrite URL slug to subdomain

Hey the community, I need you once again 馃檭

There's something I couldn't wrap my head around with my web server...聽

First things first, I'm running a Lightsail instance with a Lamp package usingbitnami.

My title may seem a bit weird. To better understand it, here's what I'm aiming to do :

  1. A user reachesdomain.fr/blog

  2. He's been internally redirected toblog.domain.fr

  3. The address bar is still showingdomain.fr/blog

That's something I was able to achieve by using this in the bitnami-ssl.conf under<VirtualHost default:443>

    ProxyPass /blog http://blog.domain.fr/    
    ProxyPassReverse /blog http://blog.domain.fr/  

So when I go todomain.fr/blogI can see the blog I'm setting up !

Now I've created myself two problems :

  • If I reachblog.domain.frI can access all of the content. Therefore, I have 2 canonical URLs for the same content, which isreallybad for SEO.

  • I can't accessdomain.fr/blog/loginfor instance...

So I'm asking you guys two questions :

  1. How to redirectproperlyblog.domain.frtodomain.fr/blog

  2. How to make it worksproperlyi.e.,/blog/loginnot showing 404 (blog.domain.fr/loginis working)

One more precision : the blog I'm setting up is running usingLaravelandJetstream馃槈

Here's what I tried to do :

I've added under the<Virtual Host *:443>for the blog vhost this line :

    RewriteEngine On
    RewriteRule ^ https://domain.fr/blog%{REQUEST_URI} [L,R=301]

I end up with the errorTOO_MANY_REDIRECTSon bothblog.domain.franddomain.fr/blog

I'm not an Apache expert or whatsoever, please be kind !

Feel free to ask any questions if what I'm trying to achieve seems hard to understand 馃槈

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now