重写Magento以获得干净的网址

时间:2014-07-28 05:44:09

标签: apache .htaccess magento mod-rewrite

如果可能的话,我想像这样重写旧的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 /
  4. 这就是我的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>
    

    提前非常感谢,

1 个答案:

答案 0 :(得分:0)

在您的apache配置文件中。例如httpd.conf中。在代码下方附加更改“目录”,其中包含VirtualHost的实际DocumentRoot。

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