[英]htaccess rewrite url for laravel project to exclude folder directory from url
I have instaledl ubuntu 16.04 server and I have lots of laravel projects in /var/www/html with numeric folder like below:我已经安装了 ubuntu 16.04 服务器,我在 /var/www/html 中有很多 Laravel 项目,其中包含如下数字文件夹:
<pre>
121744
content
app
bootstrap
config
database
public
resources
routes
storage
tests
vendor
composer.json
composer.lock
server.php
....
</pre>
<pre>
12877
content
app
bootstrap
config
database
public
resources
routes
storage
tests
vendor
composer.json
composer.lock
server.php
....
</pre>
<pre>
8798
content
app
bootstrap
config
database
public
resources
routes
storage
tests
vendor
composer.json
composer.lock
server.php
....
</pre>
As per above folder to open laravel application in the browser the url look like below:按照上面的文件夹在浏览器中打开 Laravel 应用程序,网址如下所示:
http://example.com/121744/content/public
http://example.com/12877/content/public
http://example.com/8798/content/public
The content in the url is common. url 中的内容是通用的。 I want to remove content from url so that the url should look like below:我想从 url 中删除内容,以便 url 如下所示:
http://example.com/121744/public
http://example.com/12877/public
http://example.com/8798/public
The location of .htaccess file in var/www/html/.htaccess
. .htaccess 文件在var/www/html/.htaccess
。
Please help me, how do I make htaccess do this?请帮助我,我如何让 htaccess 做到这一点?
Could you please try following.你能不能试试以下。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(\d+)/content/([\w-]+)/?$ /$1/$2 [NC,L]
In case your public
directory is fixed each time then try:如果您的public
目录每次都是固定的,请尝试:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(\d+)/content/(public)/?$ /$1/$2 [NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.