【发布时间】:2021-05-10 10:08:23
【问题描述】:
您好,我面临从 url 中删除 public/index.php 的问题。 Remove/Redirect index.php from url to prevent duplicate urls 此链接确实帮助我删除 index.php 表单 url,但我无法从 url 中删除 public/index.php。这是我下面的 htacces 代码
RewriteEngine On
#REmove index.php from url starts
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=302,NC,NE]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=302,NC,NE]
#Remove index.php from url ends
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
但是当我添加以下代码以删除 htaccess 中的 public/index.php 时,它不起作用:-
RewriteCond %{THE_REQUEST} /public/index\.php [NC]
RewriteRule ^(.*?)public/index\.php[^/] /$1? [L,R=302,NC,NE]
RewriteCond %{THE_REQUEST} /public/index\.php [NC]
RewriteRule ^(.*?)public/index\.php(?:/(.*))?$ /$1$2? [L,R=302,NC,NE]
应重定向的示例网址:
-
mydomain.com/public/index.php/something应该被重定向到mydomain.com/something(可以是任何东西 - 可以包含任何字符) -
mydomain.com/public/index.php应该被重定向到mydomain.com -
mydomain.com/index.php?anything应重定向到mydomain.com?anything(任何内容都可以包含任何字符)
请帮我解决这个问题。
【问题讨论】:
-
在你的第四个条件
mydomain.com/public/index.phpanything should be redirected to mydomain.com anything can contain any characters)你在浏览器中点击mydomain.com吗?请确认一次。 -
mydomain.com 只是出于安全目的的示例,我不在这里共享域名
-
@RavinderSingh13 我已经删除了第四个条件
-
public/内也有 .htaccess 吗? -
是的@anubhava 它在那里
标签: laravel apache .htaccess mod-rewrite url-rewriting