Jump to content

[TIP] 1.5 | 1.6 and Custom .htaccess


Recommended Posts

Many users noticed that they are unable to customize their .htaccess using the back office as could be done in release 1.4.

There has been some confusion on the board (me included) that if we customize the .htaccess and FTP to our shop that PrestaShop would overwrite it during .htaccess generation.

This is not correct!

PrestaShop will not overwrite the custom changes we make if we place the custom .htaccess definitions in the correct places.

Example: Top of .htaccess

Your custom code goes here

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

Example: Bottom of the .htaccess



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

Your custom code

Happy PrestaShopping

 

  • Like 13

Share this post


Link to post
Share on other sites

You enable; Automatically redirect to Canonical URL

 

But in small print Prestashop warns - Recommended, but your theme must be compliant

 

My theme, (purchased from TM), is not compliant because if I try to access a product page with www, it doesn't "Automatically redirect to Canonical URL".

 

So this tip is only necessary if your theme is not compatible with the redirect provided by Prestashop.

 

Using the tip provided by elpatron,

 

Put the following code above the reserve line, so that it will not be overwritten by Prestashop. Remember to change yoursite.com.

 

RewriteEngine On

RewriteCond %{HTTP_HOST} !^yoursite.com$

RewriteRule (.*) http://yoursite.com/$1 [R=301,L]

 

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

Share this post


Link to post
Share on other sites

  • 4 months later...

You enable; Automatically redirect to Canonical URL

 

But in small print Prestashop warns - Recommended, but your theme must be compliant

 

My theme, (purchased from TM), is not compliant because if I try to access a product page with www, it doesn't "Automatically redirect to Canonical URL".

 

So this tip is only necessary if your theme is not compatible with the redirect provided by Prestashop.

 

Using the tip provided by elpatron,

 

Put the following code above the reserve line, so that it will not be overwritten by Prestashop. Remember to change yoursite.com.

 

RewriteEngine On

RewriteCond %{HTTP_HOST} !^yoursite.com$

RewriteRule (.*) http://yoursite.com/$1 [R=301,L]

 

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

 

Thank you for this TIP

before it I had problems redirecting to www, and now is working properly. However Im a little afraid, because in the code appears twice RewriteEngine on. one above the comment and another one below. is safe doing this?

 

by the way, I'm using the official theme of ps 1.5.4.1, why htacess redirecting is not working well?

 

My only pending thing is the SEO words are not redirecting. I mean: /best-sales is not working, only is working the redirected friendly url /ventas. If I type /ventas I access, but If i type the original one (best-sales) I received 404 error

Do you have idea how to solve?

 

Thank you a lot!

Please excuse me for my bad english

Share this post


Link to post
Share on other sites

  • 1 month later...

Hi mr-t,

 

I suggest you open a new forum post deatiling what you are trying to accomplish.

 

Hi Vincente, I have included the link to the new topic in my previous post.

  • Like 1

Share this post


Link to post
Share on other sites

  • 2 months later...

Hi,

 

Thanks, its awesome post.

 

If i will add my custom code before or after main code ends and if .htaccess overwrite from out sources then our codes remains in file or it also overwrite???

 

waiting for your kind reply.

 

Thanks...

 

as long as native PS is the updater of the .htaccess file then your custom changes will be preserved, assuming you put them in the correct place as noted above.

  • Like 1

Share this post


Link to post
Share on other sites

Well you can hardly imagine how often I had to manually change out httaccess since I had to tweak the php settings of our 'shared' host....

 

Thanks alot for this tipp. Some srutiny is always helpfull :)

 

 

PS:

Does it hartm even if we use a 'compatible' theme that is also customized by us?

Share this post


Link to post
Share on other sites

  • 1 month later...

I've tried editing my .htaccess after the last *end* comment thingy, but im gettin an Internal Server Error when I try to load the website after.

 

It's a simple 301 redirect:

//301 Redirect Old File
Redirect 301 http://www.domain.com/nl/category/product1.html http://www.domain.com/product1.html

I've tried to redirect 3 old pages this way (I don't have many products in my store). The old pages don't exist anymore, so i'd like them to redirect to the new page...

 

Any suggestions?

 

Share this post


Link to post
Share on other sites

  • 2 weeks later...

 

I've tried editing my .htaccess after the last *end* comment thingy, but im gettin an Internal Server Error when I try to load the website after.

 

It's a simple 301 redirect:

//301 Redirect Old File
Redirect 301 http://www.domain.com/nl/category/product1.html http://www.domain.com/product1.html

I've tried to redirect 3 old pages this way (I don't have many products in my store). The old pages don't exist anymore, so i'd like them to redirect to the new page...

 

Any suggestions?

 

 

here is an example...in 1.5, not sure when it was introduced but at the product level you can tell ps to redirect to t 404 or 301/302 to another product. 

redirectMatch 301 ^/link-to-your-product.html$ http://yourdomain/any-link
  • Like 1

Share this post


Link to post
Share on other sites

  • 3 months later...

I have about 650 url from old shop which need to be redirected to new Prestashop path, if .htaccess file is added with that many urls. website will be slow down, any other suggestions ? or module

Share this post


Link to post
Share on other sites

I have about 650 url from old shop which need to be redirected to new Prestashop path, if .htaccess file is added with that many urls. website will be slow down, any other suggestions ? or module

Hey nish,

 

you can check with folks here: http://www.presto-changeo.com/

 

also you may want to search around a bit for some module and/or trick that will help you get this done.  I would think the .htaccess is going to be the fastest because if module solution then it will have same if not more overhead...but I could be wrong. :)

Share this post


Link to post
Share on other sites

  • 3 weeks later...

 

fyi if you are getting crawled by semalt dot com (they suck)  put this in the top or bottom of your .htaccess file

# block visitors referred from semalt.com
RewriteEngine on
RewriteCond %{HTTP_REFERER} semalt.com [NC]
RewriteRule .* - [F]

 

Who are they? I have recently started noticing them in my backlinks a lot in awstats. But there are so many other .ru sites who also keep referring, i dont know if we can ever solve this issue.

Edited by indus (see edit history)

Share this post


Link to post
Share on other sites

Who are they? I have recently started noticing them in my backlinks a lot in awstats. But there are so many other .ru sites who also keep referring, i dont know if we can ever solve this issue.

 

don't really know who they are but they IMHO are bad bots.  I added the above to my shop as they were doubling my visitors count (yesterday).  It's best to always search outside of ps for this type of issue/resolution. :)

  • Like 1

Share this post


Link to post
Share on other sites

  • 10 months later...
  • 2 months later...

Further to these issues, I have a strange problem regarding placing code outside the comments in .htaccess in PS 1.5.6.2.

 

I have around 3000 redirects in my .htaccess file, and for some reason, Prestashop inserts it's code to the bottom of the file every time I update it.

I've even tried editing the file and moving the redirects to the bottom of the page, but every time the htaccess is regenerated it changes it back.

 

This means that I end up with all my redirects in the file before it gets to the prestashop bit, which really seems to slow performance of my site. Any ideas?

Share this post


Link to post
Share on other sites

  • 1 month later...

hi  i  transfer my prestashop with filezilla and databases . i receive this error 

Not Found

The requested URL /en/ was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

 

 when i try to upload the .htaccess file with these lines , the page is white and and not display the page, anyone can help please?

 

# ~~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.theiashop.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]
 
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
 
# Images
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
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]
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]
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]
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]
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]
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]
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
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
RewriteRule ^.*$ - [NC,L]
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>
 
#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

Share this post


Link to post
Share on other sites

  • 1 month later...

Is it ok to have "RewriteEngine On" twice in the code? Once at the beginning in the custom code and once later in the original PS generated code??

Thanks :)

 

 

You enable; Automatically redirect to Canonical URL

But in small print Prestashop warns - Recommended, but your theme must be compliant

My theme, (purchased from TM), is not compliant because if I try to access a product page with www, it doesn't "Automatically redirect to Canonical URL".

So this tip is only necessary if your theme is not compatible with the redirect provided by Prestashop.

Using the tip provided by elpatron,

Put the following code above the reserve line, so that it will not be overwritten by Prestashop. Remember to change yoursite.com.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^yoursite.com$
RewriteRule (.*) http://yoursite.com/$1 [R=301,L]

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

Share this post


Link to post
Share on other sites

Is it ok to have "RewriteEngine On" twice in the code? Once at the beginning in the custom code and once later in the original PS generated code??

Thanks :)

I don't think it will cause a problem, as it just directs the RewriteEngine to be operating, so should be fine.

Share this post


Link to post
Share on other sites

 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More