Jump to content

Where To Add Redirect In Existing Htaccess File


ovm

Recommended Posts

I need to redirect my primary domain to a folder.  I have found the code but it seems to apply to an empty or new htaccess file.  Where in the existing script do I add the redirect?

 

This is the script I found to redirect my primary domain to a folder called shop:
RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$
RewriteCond %{REQUEST_URI} !^/shop/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(*)$ /shop/$1
RewriteCond %{HTTP_HOST} ^(www.)?primarydomain.com$
RewriteRule ^(/) ?$ shop/index.php [L]

 

This is my existing script.  Where in the existing script do I add the redirect?

RewriteOptions inherit

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

RewriteEngine on

#Domain: www.primarydomain.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]

RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
</IfModule>

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff
<IfModule mod_headers.c>
    <FilesMatch "\.(ttf|ttc|otf|eot|woff|svg)$">
        Header add Access-Control-Allow-Origin "*"
    </FilesMatch>
</IfModule>

#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404

# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

RewriteCond %{HTTP_HOST} ^primarydomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.primarydomain\.com$
RewriteRule ^www\.primarydomain\.com$ "https\:\/\/www\.primarydomain\.com\/shop\/" [R=301,L]

 

I have tried appending to the bottom but that didn't work.  I also tried inserting it here and there but so far I haven't found anything that will work.  Also, it looks like that last line is including the shop folder some how (http to https rewrite?).

 

my primary domain is overspraymarketdotcom.  It needs to redirect to overspraymarketdotcom/shop. 

Can someone please help me out??  It's the last thing I need to do to formally launch.

Edited by ovm (see edit history)
Link to comment
Share on other sites

Can anyone please help with this?  GoDaddy is completely useless when it comes to htaccess.  I'm stuck!  I know the domain can be redirected to a folder.. I just can't figure out where to put the code in the existing script.

 

(at this point, I've inserted the code in every possible location in the htaccess, cleared browser cache, and nothing.. I can't get the primary domain to redirect to the folder..  I'm curious as to what that last line in my existing script means, it appears to be redirecting the primary domain to a secured folder.. every page on my site is secured so that portion seems to be working. )

Edited by ovm (see edit history)
Link to comment
Share on other sites

Thank you for responding!  Yes, I've tried it just after RewriteEngine On; and to make absolutely sure, I tried it again just now.  Cleared ps and browser cache in both Chrome and Mozilla and still get "coming soon" page.  Is it possible that last line in the existing script is calling the rule to be read first?  (I have no idea!)  And that last line appears to be rewriting to https subfolder shop.. (my whole site is secure.. could it be that the last half of the line is miswritten?  Again, I have NO idea.. I'm just theorizing.  [files have 644/755 permissions as appropriate.]

Edited by ovm (see edit history)
Link to comment
Share on other sites

I pulled my htaccess file over with filezilla today and opened it in notepad++.  I opened something that looks nothing like what I have been working on (see below) but when I go to my cpanel and open the file in code editor, I get what I posted above.  wth??  Anybody know what that is about??  And what's more, it looks like I'm on some kind of timeline with the images set to expire.  I guess I have a module that will expire or something?  grrrrrrrrrrrrr  So!  Does PS keep the code outside of their comments or not?  Why do I see the below code when looking at it in notepad++ but the above code when I edit directly in cpanel?  I am lost!

 

RewriteOptions inherit
# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
 
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
 
RewriteEngine on
 
#Domain: www.primarydomain.com
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule . - [E=REWRITEBASE:/shop/]
RewriteRule ^api$ api/ [L]
 
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
 
# Images
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
 
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} ^www.primarydomain.com$
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
 
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|svg)$">
Header add Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
 
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-otf "access plus 1 year"
</IfModule>
 
<IfModule mod_headers.c>
Header unset Etag
</IfModule>
FileETag none
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript font/ttf application/x-font-ttf font/otf application/x-font-otf font/opentype
</IfModule>
</IfModule>
 
#If rewrite mod isn't enabled
ErrorDocument 404 /shop/index.php?controller=404
 
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
Link to comment
Share on other sites

Ok so let's reason this out..  (let's disregard the notepad version and consider the cpanel code editor version)

 

the only place that I am aware of to input where the store is located in the backend, is multistore>shopurls.  I am specifically asked what folder the store is in and what the final URL is to be.. thus PS is auto generating the redirect.

 

If that is true, the only place in the htaccess script that says the name "shop" is in the last line... the error has to be in that line

RewriteRule ^www\.primarydomain\.com$ "https\:\/\/www\.primarydomain\.com\/shop\/" [R=301,L]

(again, the whole site is secure - that portion must be working because I don't see a rule for it anywhere else)

 

AND (now here's the kicker) if all of the above is true, at some point PS will auto-generate htaccess again and overwrite whatever correction may eventually be applied.

 

AARRGGHH I'm STUCK

Link to comment
Share on other sites

  • 1 month later...

WOW! This was unpleasant suprise!

 

Seems like that this PrestaShop community ain't no community.

 

I found myself at the same point. I made first shop and just before launch it's suddenly stop working - i did see categories but not product pages. I try to figure out whats wrong but i decided to make it over from a scratch. Second attempt ended this problem. Backoffice works fine but frontpage doesn't open.

 

I figure out that it has something to do with the https access. So i thought that this forum would help but now it seems that it doesn't.

 

Probably i change application - i'm already running late.

Link to comment
Share on other sites

Hello PresSh00p,

Unfortunately, I haven't had much success getting help in the forums.  I am happy to email you my htaccess files.  They may help you figure it out.  They are too long to post here.  I have two (one in the folder where my store is located and one in the root folder).  Prestashop auto-generates the htaccess based on info you input in the backend.  I wish I could be more help but I forget what I had to do to get it working.  I recommend DesignHaus!  They helped me move my store to a designated folder, get my htaccess straight and fixed the Amazon module for me.  https://dh42.com/

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...