【问题标题】:Rewrites for Magento to get clean urls为 Magento 重写以获得干净的 url
【发布时间】:2014-07-28 05:44:08
【问题描述】:

如果可能的话,我想像这样重写旧的 Magento 网址:

  1. www.domain.tld/index.php => www.domain.tld/
  2. www.domain.tld/index.php/category/ => www.domain.tld/category/
  3. www.domain.tld/index.php/category/subcategory/ => www.domain.tld/category/subcategory/

这就是我的 Magento .htaccess 现在的样子(不重定向上述任何内容)。

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on    
RewriteBase /

#RewriteRule ^api/([a-z][0-9a-z_]+)/?$ api.php?type=$1 [QSA,L]
RewriteRule ^api/rest api.php?type=rest [QSA,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
#RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
#RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
#RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

# 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} !(.*)/$
#ADD SLASH IF MISSING AND THEN REDIRECT
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]

</IfModule>

提前非常感谢,

【问题讨论】:

    标签: apache .htaccess magento mod-rewrite


    【解决方案1】:

    在您的 apache 配置文件中。例如httpd.conf。将下面的代码添加到 VirtualHost 的实际 DocumentRoot 中更改“目录”。

    <Directory /var/www/html/www>
        AllowOverride All
    </Directory>
    

    【讨论】:

    • 谢谢,但这已经在 vhost 文件中了。 .htaccess 文件已处理,但不会按我的意愿重定向(见上文)。我可能需要更多指令来实现这一目标?还有其他线索、提示或技巧吗?
    • 在 Magento 中配置干净的 URL,您的请求会起作用。使用默认的 .htaccess 文件并验证。
    • 感谢您的意见 KNOWARTH。内部链接按预期工作。问题是,我有指向该网站的旧链接,这弄乱了我想要的干净网址。例如:一个站点链接到 www.domaian.tld/index.php,并且当访问者使用链接时,如果链接被访问者使用,我希望 htaccess 重定向回根目录,没有文件名 index.php 和或没有查询字符串(剥离)。可能吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多