【发布时间】:2021-02-05 09:34:26
【问题描述】:
我想从 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:此文件位于“public/”文件夹中。该项目在 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>
【问题讨论】:
-
@anubhava 我在从 DocumentRoot 中删除 index.php/mystore 后尝试过,但仍然在 url mystore 中未删除。当我运行 pragnastore.sliderstock.local/pragnastore 这个网址时,它不会删除 /pragnastore。
-
它应该重定向到相同但它只是删除 /pragnastore 并显示像pragnastore.sliderstock.local这样的url
-
是的,我通过虚拟主机创建了这个域。最初是“example.com/mystore”,我需要将商店名称显示为子域,例如“mystore.example.com”。
标签: regex laravel apache .htaccess subdomain