how to modify this mod rewrite into the url I want?

核能气质少年 提交于 2019-12-13 04:36:01

问题


I actually got an answer that if I want to change my url from www.mydomain.com/laravel4/public/posts into www.mydomain.com/posts

this is what I have to do with my .htaccess

RewriteEngine On

RewriteRule !^laravel4/public/ /laravel4/public%{REQUEST_URI} [L,NC]

but I have another question if I want the url to be www.mydomain.com/laravel4/posts which takes out the public what should I modify? I thought taking out the laravel4 in the code above would work but doesn't seem that easy :(


回答1:


Ideally you should move the Laravel install out of the document root and just move the contents of the public folder into your document root and edit the index.php and bootstrap/paths.php accordingly, or alternatively set the document root to the public folder of Laravel, some hosts will change the document root for you if you open a support ticket.

However thats not always possible depending on your host, and most people will tell you to go off and find a better host, but again, thats not always an option.

Below is a .htaccess example you can use to rewrite all URLs to the public/index.php of Laravel, but be warned, this isn't a very secure way to setup Laravel, and anyone could potentially access any of your configuration and other files that exist in your document root, exposing your database passwords and secret keys used to encryption.

RewriteEngine On
RewriteRule ^ laravel4/public/index.php [L]

Updated as per request

RewriteEngineOn
RewriteRule ^laravel4/.* laravel4/public/index.php [L]



回答2:


You can use this rule:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/laravel4/public(/|$) [NC]
RewriteRule ^laravel4/(.*)$ /laravel4/public/$1 [L,NC]


来源:https://stackoverflow.com/questions/21060471/how-to-modify-this-mod-rewrite-into-the-url-i-want

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!