简体   繁体   中英

primary domain to subfolder without folder name in url

I've 2 websites

  1. Shopping Website (Magneto 1)
  2. Blogging website (Laravel)

and I've single domain for example http://www.shopnow.com/ , so i need to set .htaccess file in root directory so that

  1. http://www.shopnow.com ==> public_html/shop
  2. http://blog.shopnow.com ==> public_html/blog

I've tried .htaccess in root folder as

# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?shopnow.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
#RewriteCond %{REQUEST_URI} !^/shopnow/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /shopnow/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
 RewriteCond %{HTTP_HOST} ^(www.)?shopnow.com$
RewriteRule ^(/)?$ /shopnow/index.php [L] 

You have to change your apache's site configuration. Edit your post with it, go to /etc/apache2/sites-enabled/ and look for your file. What you have to do is look for DocumentRoot (it should say /var/www/html if you didn't change it) and change it to YOUR_HTML_ROOT/public_html/shop and then copy and past the same file, change the value pointing to the other site to the new.

Here is an example: 000-shop.conf

<VirtualHost *:80>
        ServerName shopnow.com
        ServerAlias www.shopnow.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/public_html/shop

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

And for blog: 001-blog.conf

<VirtualHost *:80>
        ServerName blog.shopnow.com
        ServerAlias www.blog.shopnow.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/public_html/blog

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Remember that you must modify your DNS zone and add a CNAME pointing to your domain, use @ and as value use blog . Also remember that you have to edit this file to match your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM