简体   繁体   English

漂亮的URL Laravel 5.4

[英]pretty urls laravel 5.4

Hi I am facing issues with settng pretty urls withput public in url but it is not working for me. 嗨,我遇到了settng漂亮的url并在url中放入public的问题,但这对我不起作用。

I already tried 我已经试过了

Laravel 5.2 Pretty URLs , Laravel 5 - Remove public from URL Laravel 5.2漂亮的URLLaravel 5-从URL删除public

and more similar urls but nothing seems to work for me. 和更多类似的网址,但似乎对我没有用。

I am using wamp, windows 8 我正在使用Wamp,Windows 8

I have make sure mod_rewrite is on, and is working properly. 我确保已打开mod_rewrite,并且工作正常。

Here is my htaccess on root. 这是我的htaccess根目录。

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

my htaccess in test inside public folder 我的htaccess在公用文件夹中的测试中

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

I have also tried pasting the htacess from public folder on root folder and removed the one from public folder but it dint work 我也尝试过将htacess从公用文件夹粘贴到根文件夹上,并从公用文件夹中删除了它,但这确实可行

actually the error which occurs is that my routes file skips all the patterns say if I have something like Route::get('/api/login', 'api@login') then it does works with urls containing public but when I remove public from url all the patterns are skipped. 实际上发生的错误是我的路由文件跳过了所有模式,如果我有类似Route :: get('/ api / login','api @ login')之类的代码,那么它确实适用于包含public的url,但是当我删除时从url公开所有模式。 and it shows 404 它显示404

I made sure all the requests are reaching public/index.php and mysterious thing is that when I print 我确保所有请求都到达public / index.php,而奇怪的是,当我打印时

var_dump(Request::root());

in routes.php it for url with public it says http://localhost/folderName/subFolderName/public but for the urls without public it says http://localhost/ and I think this is the reason why my patterns in routes file are not working. 在routes.php中,对于带有公共URL的URL,它说http:// localhost / folderName / subFolderName / public,但是对于没有公共URL,它的URL说http:// localhost / ,我认为这就是为什么我的路由文件中的模式是不工作。

PS I have set the title pretty urls laravel 5.4 instead of laravel routes not working because I think it is .htaccess which I needs to configure properly to get this working. PS我已经设置了标题pretty urls laravel 5.4而不是laravel routes not working因为我认为这是.htaccess,我需要对其进行适当配置才能使其正常工作。

I do not want to change the folder structure because I believe in that there is some reason for which it is like this and There should be some work around for this. 我不想更改文件夹的结构,因为我相信这是有某种原因的,因此应该解决一些问题。

Regarding setting vhosts I wont be able to do this on server (For I do not have the rights) so there is no use of setting a vhost on local as a work around as in login run I have to solve this. 关于设置虚拟主机,我将无法在服务器上执行此操作(因为我没有权限),因此没有必要像在登录运行中那样在本地设置虚拟主机来解决此问题。

Try this in your public/.htaccess 在您的public / .htaccess中尝试

RewriteRule ^ /public/index.php [L]

And the .htaccess in root 和根目录下的.htaccess

RewriteRule ^(.*)$ /public/$1 [L]

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

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