我安装了 Magento,想知道如何将 domain.tld/index.php 重定向到 domain.tld?
我想删除 index.php 然后 301 回到 root。我有很多旧链接,这些链接给我重复的内容和丑陋的网址等。旧链接示例:
domain.tld/index.php?controller=best_sales
在 .htaccess 中,我有以下内容,但它不起作用
RewriteRule .* index.php [L]
谢谢:)
编辑:
感谢你们两位的回答,但我仍然无法让它工作。 尝试进行任何更改时,我收到 404 - Not Found。
这是我的完整 .htaccess,也许有一些错误或配置错误导致它无法正常工作?
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
// REMOVE HOME REWRITE FROM MAGENTO
RewriteRule ^home/?$ /? [R=301,L,NC]
// ADD WWW TO NONE WWW FOR BOTH HTTPS AND NONE HTTPS
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
// REDIRECT ALL .HTML FILES AND ALL .HTML/ FILES WITH TRAILING SLASH
RewriteRule ^google[0-9a-f]+.html$ - [L]
RewriteRule (.+)\.html$ /$1/ [L,R=301]
RewriteRule (.+)\.html\/$ /$1/ [L,R=301]
// ADD TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
// TRAILING SLASH CHECK
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
// CHECK IF REDIRECT POINTS TO A VALID FILE
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
// SEND TO INDEX.PHP FOR CLEAN URLS
#RewriteRule ^(.*)$ index.php? /$1 [L,QSA]
#REWRITE EVERYTHING ELSE TO INDEX.PHP
RewriteRule .* index.php [L]
最佳答案
将此规则作为您的第一条规则保存在 RewriteEngine On
行下方,以从您的 URL 中删除 index.php
:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
关于regex - 将 domain.tld/index.php 重定向到 domain.tld(删除 index.php,然后删除 301),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25131700/