繁体   English   中英

将domain.tld / index.php重定向到domain.tld(删除index.php,然后删除301)

[英]Redirect domain.tld/index.php to domain.tld (remove index.php and then 301)

我有一个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]

我假设没有任何规则它已经显示domain.tld/?controller=best_unicorns 如果查询字符串前面的url 以'index.php'结尾 ,则需要重定向到不带index.php的url。 实际上,域名和查询字符串之间的部分只包含'index.php'。

你需要使用R (重定向)标志:

RewriteRule ^index\.php$ / [R,L]

删除你的其他尝试。 如果此规则有效,请将标志更改为[R=301,L]以使其成为永久标志。 这样,浏览器和搜索引擎都知道只在一个地方查看。

暂无
暂无

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

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