PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 3, 2022

[FIXED] How can I convert a folder into a sub domain?

 July 03, 2022     .htaccess, mod-rewrite, multisite, redirect, subdomain     No comments   

Issue

I have a website that looks like this (the Ferrari is not a physical folder is an alias virtual):

www.example.com/en/ferrari

and I would like to convert this site into a sub-domain, like so:

ferrari.example.com

or something like:

ferrari.example.com/en/


The idea is to have all sub-pages from the Ferrari section working inside the sub-domain.

I don't know if this is even possible, all my .htaccess test didn't worked out. I am searching for a re-write rule but I don't seem to find it.

EDIT:

Let me rephrase the question, I don't want to REDIRECT from example.com/ferrari to ferrari.example.com

What I want is to show the example.com/ferrari site when someone opens ferrari.example.com. That is the difficult part. If someone opens ford.example.com, I want to show all the pages that are inside example.com/ford.


Solution

You can use that in your root .htaccess:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^ferrari\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/en/ferraricars [NC]
RewriteRule ^(?:en/)?(.*) en/ferraricars/$1 [NC,L]

Work with ferrari.example.com/en/other and ferrari.example.com/other -> example.com/en/ferraricars/other



Answered By - Croises
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing