I want to create subdomain from the first parameter of URL and then remove that parameter.
Desired result:
http://www.example.com/mystore -> http://www.mystore.example.com
For this first I have created virtual host for mystore.example.com
Now I am trying to remove this mystore parameter from url.
I tried below changes in htaccess. Please check.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/mystore/
Virtual Host:
<VirtualHost *:80>
ServerAdmin admin@gmail.com
ServerName mystore.example.local
ServerAlias www.mytore.example.local
DocumentRoot /var/www/html/Projectname/public/index.php/mystore
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess: This file is inside "public/" folder. This project is in laravel.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes +FollowSymLinks
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^mystore(/.*)?$ http://www.mystore.example.com$1 [NC,L,R=301,NE]
</IfModule>
You may use this rule in site root .htaccess of www.example.com
:
RewriteEngine On
RewriteCond %{HTTP_HOST} pragnastore\.sliderstock\.local$ [NC]
RewriteRule ^pragnastore(/.*)?$ http://pragnastore.sliderstock.local$1 [NC,L,R=301,NE]
Make sure to use this rule just below RewriteEngine On
line.
Using this link , I solved it with Laravel routing changes. So for this, First I created virtual host and then do this changes in my routing web.php
Route::group(array('domain' => '{subdomain}.website.com'), function ($subdomain) {
Route::get('/', 'controller@method');
});
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.