.htaccess-rewrite:从url中删除参数



我想从URL的第一个参数创建子域,然后删除该参数。

期望结果:

http://www.example.com/mystore          -> http://www.mystore.example.com

这是我第一次为mystore.example.com创建虚拟主机

现在我正试图从url中删除这个mystore参数。

我在htaccess中尝试了以下更改。请检查。

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/mystore/

虚拟主机:

<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:此文件位于";公共/";文件夹这个项目进展顺利。

<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>

您可以在www.example.com:的站点根目录.htaccess中使用此规则

RewriteEngine On
RewriteCond %{HTTP_HOST} pragnastore.sliderstock.local$ [NC]
RewriteRule ^pragnastore(/.*)?$ http://pragnastore.sliderstock.local$1 [NC,L,R=301,NE]

请确保在RewriteEngine On行下方使用此规则。

使用这个链接,我通过Laravel路由更改解决了这个问题。因此,首先我创建了虚拟主机,然后在我的路由web.php 中进行更改

Route::group(array('domain' => '{subdomain}.website.com'), function ($subdomain) {
Route::get('/', 'controller@method');
});

最新更新