0

I have a Magento website hosted in a managed server where we need to use two .htaccess files, the first one is needed to redirect all request to a subfolder /current/src/ and is placed directly in public_html which is the web root

RewriteEngine On

RewriteRule ^$ /current/src/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !^/current/src/
RewriteRule ^(.*)$ /current/src/$1

The second .htaccess which come with Magento 1.9 and slightly modified, directly placed in /current/src/

PS: I only included the part that deal with URL Rewrite

######################################################################### 
################## Coding Basics Magento .htaccess File #################
# http://codingbasics.net/magento-htaccess-file-optimized-speed-security-seo/ #
######################################################################### 

##### Block unwanted Crawler Bots that clog your server #####

        RewriteCond %{HTTP_USER_AGENT} MJ12bot
        RewriteRule .* - [F]
        RewriteCond %{HTTP_USER_AGENT} 80legs [NC]
        RewriteRule ^ - [F]

 ##### Search Engine redirects and rewrites for SEO purposes #####

<IfModule mod_rewrite.c>
       Options +FollowSymLinks
       RewriteEngine on
       RewriteBase /

# I added this bloc to add a trailing Slash to every URL except 
# any URL that contains any Query String for SEO purpose
########################################################################
       RewriteCond %{ENV:REDIRECT_STATUS} ^.
       RewriteCond %{QUERY_STRING} ^(.*)$
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_URI} !\..+$
       RewriteCond %{REQUEST_URI} !/$
       RewriteRule ^(.*)$ $1/ [R=301,L,QSA]
########################################################################

       RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
       RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteCond %{REQUEST_FILENAME} !-l
       RewriteRule .* index.php [L]
</IfModule>
  • The .htaccess file below works fine without my added bloc, now I succeed to to keep any original URL that contain a trailing / like:

{Server_URL}/en/blog/

  • Category page without trailing /

{Server_URL}/en/category/sub-category

301 redirection to

{Server_URL}/en/category/sub-category/

and

{Server_URL}/en/category/sub-category?dir=asc&limit=36&order=price

301 redirection to

{Server_URL}/en/category/sub-category/?dir=asc&limit=36&order=price

  • Product page without trailing /

{Server_URL}/en/product-url-key

301 redirection to

{Server_URL}/en/product-url-key/

301 redirection to

{Server_URL}/en/product-url-key

... ERR_TOO_MANY_REDIRECTS

  • Where are these .htaccess files located? – MrWhite Jan 21 '16 at 17:38
  • @w3d I edited my question so you can see where the two .htaccess files are placed in the server – Proxium Jan 21 '16 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.