php - laravel 尾部斜杠重定向到本地主机

标签 php regex .htaccess mod-rewrite trailing-slash

当我尝试这个时

http://localhost/Testlaravel/public/users/login

它有效。但是当我尝试

http://localhost/Testlaravel/public/users/login/ 

它将我重定向到

http://localhost/users/login/

知道为什么吗?

这是我的 htaccess 文件

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

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

最佳答案

将您的代码更改为:

Options -MultiViews
RewriteEngine On
RewriteBase /Testlaravel/public/

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ $1 [L,R=301]

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

关于php - laravel 尾部斜杠重定向到本地主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21735527/

相关文章:

regex - 如何判断正则表达式中的匹配项之间是否存在三个或更多字符?

php - Apache - 浏览任何域 URL 都指向同一文件夹

apache - 基于ip的mod_rewrite

apache - Rewriterule 从旧论坛永久移至新论坛

php - 如何在 redis 中使用 GEOADD 存储额外数据

php - 权限被拒绝 :/var/www/abc/. htaccess pcfg_openfile : unable to check htaccess file, 确保它是可读的?

php - fatal error : Call to a member function result() on string when building a PHP filtering system

php - 如何在drupal8中将文件uri转换为相对路径

ios - 如何编写正则表达式来查找 XCode 项目中的所有字符串

python - 正向lookbehind正则表达式未按预期匹配