简体   繁体   English

从网址中删除目录名称

[英]Remove directory names from url

I have a new Project in Lumen which needs to be deployed to the Staging server and i have done it. 我在Lumen中有一个新项目,需要将其部署到登台服务器,并且已经完成了。 I am facing issues with removing the names of directories from the URL. 我在从URL删除目录名称时遇到问题。 My project Directory is like this: 我的项目目录如下:

DIR - ProjectName
   DIR - ProjectName {Lumen files inside this directory}
     DIR - app
     DIR - bootstrap
     DIR - database
     DIR - public
     DIR - resources
     DIR - storage
     DIR - tests
     DIR - Vendor

so currently to view my application i need to enter a url like this : 因此,当前要查看我的应用程序,我需要输入如下网址:

http://stagingserverdomain.com/ProjectName/ProjectName/public/login

However i would like my url to be like this: 但是我希望我的网址是这样的:

http://stagingserverdomain.com/ProjectName/login

I have tried the many answers form SO but it does not work. 我已经尝试过SO的许多答案,但是它不起作用。

Use this: 用这个:

RewriteEngine On
RewriteRule ^Projectname/login$ /ProjectName/ProjectName/public/login [L]

It should leave you with the following URL: 它应该为您提供以下URL:

http://stagingserverdomain.com/ProjectName/login

Great question! 好问题! Add this Apache httpd RewriteRule to the appropriate server definition inside your httpd.conf file: 将此Apache httpd RewriteRule添加到httpd.conf文件中的相应服务器定义中:

RewriteEngine On
RewriteRule ^/(ProjectName)/((?!\1).*)  /$1/$1/public/$2

Alternatively, add this to a .htaccess file at the root of your web-server, eg, where the first ProjectName directory is located: 或者,将其添加到Web服务器根目录下的.htaccess文件中,例如,第一个ProjectName目录所在的位置:

RewriteEngine On
RewriteRule ^(ProjectName)/((?!\1).*)   $1/$1/public/$2

Alternatively, add this to a .htaccess file within the first ProjectName directory (where the second ProjectName directory is located): 或者,将其添加到第一个ProjectName目录(第二个ProjectName目录所在的目录)内的.htaccess文件中:

RewriteEngine On
RewriteRule ^((?!ProjectName).*)    ProjectName/public/$1

Alternatively (and this is the recommended course of action), switch to nginx , and do this: 或者,(建议这样做),切换到nginx ,然后执行以下操作:

location /ProjectName {
    rewrite ^/([^/]+)/((?!\1).*)$   /$1/$1/public/$2;
}

The above code ensures that the rewrite will only happen if your URLs don't already contain ProjectName/ProjectName (using the lookahead assertions of PCRE , which is the library both NGINX and Apache use for support of the regular expressions ), so, there won't be any infinite redirect loops. 上面的代码确保仅当您的URL不包含ProjectName/ProjectName时才进行rewrite (使用PCRE先行断言NGINXApache均使用该库来支持正则表达式 ),因此,不会是任何无限的重定向循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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