Jump to content

[SOLVED] Canonical URL Issue with Friendly URL's in 1.5.2


Recommended Posts

After much trial and error (because of a buggy 3rd party module) I managed to get Canonical URL's (located in Preferences > SEO & URLs) to work......sort of.

 

With Canonical URL and Friendly URL's switched on www.mysite.com redirects to mysite.com without any problems.

 

However, if I try to visit a product link directly, www.mysite.com/60-category-product does not redirect properly and gets stuck in a loop eventually throwing this error in Firefox:

 

"The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

 

With friendly URL's turned off, www.mysite.com/index.php?id_product=60&controller=product

redirects successfully to mysite.com/index.php?id_product=60&controller=product

 

Anyone know what's going on and if there's a fix, please?

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

I tried this with canonical URL Module version 1.3.

Unfortunately it hasn't resolved the issue.

 

I tried it with the canonical URL option in 1.5 enabled and disabled.

Aso tried disabling apache multiviews with no change.

 

Once again www redirects properly when friendly URL's are switched off.

 

Anyone have any more thoughts?

Link to comment
Share on other sites

I can confirm this.

 

http://www. your-domain.com/ -> http://your-domain.com/en/

 

The above works, however, with friendly url on,

 

http://www. your-domain.com /en/ -> 404 error page

 

I used the following work around to make it work until we get a bug fix.

 

At the top of your htaccess, you will see this,

 

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{HTTP_HOST} ^your-domain.com$

RewriteRule . - [E=REWRITEBASE:/]

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

 

Try adding the following code underneath, it works for me.

 

RewriteEngine On

RewriteCond %{HTTP_HOST} !^your-domain.com$

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

  • Like 2
Link to comment
Share on other sites

You nailed it Bill!

Thank you so much. I have spent hours on this

 

So just for anyone following this thread this is what I did:-

 

1. In my prestashop back office I went to Preferences > SEO & URLs

I made sure that Friendly URL was "yes"

Automatically redirect to Canonical URL was "yes"

Disable apache multiviews was "no"

 

 

2. I FTP's into my site to the public_html folder where the .htaccess file resides

 

3. I downloaded the file to my desktop

 

4. I edited the file in Notepad++ (for those that haven't used it, an open source text editor that handles programme code much better than notepad)

 

5. I deleted the following lines beneath "rewrite engine on" :-

RewriteCond %{HTTP_HOST} ^your-domain.com$

RewriteRule . - [E=REWRITEBASE:/]

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

 

6. I added the following lines beneath "rewrite engine on" :-

RewriteCond %{HTTP_HOST} !^your-domain.com$

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

 

All the redirects were now working properly.

 

N.B. What to be very aware of is that if you subsequently make any changes to the settings in step one, your .htaccess file will be automatically rewritten and your redirects will stop working.

In this case you just repeat the above process.

 

I was thinking about changing the .htaccess file permission to "read only" (chmod 444) to stop it from happening.

Would that break anything?

 

Thanks again!

dee

  • Like 1
Link to comment
Share on other sites

I was thinking about changing the .htaccess file permission to "read only" (chmod 444) to stop it from happening.

Would that break anything?

 

Good idea. Never tried this always left default. But none should write in there anyway, rx rights seems enough.

It is not like we need to regenerate the .htaccess every day.

Anyway worse case scenario, it will fail on you and you will have to replace with the file you will backup before making the changes <_<

Try & Fail rulez! :D

 

 

Good Luck!

 

Cheers!

Link to comment
Share on other sites

Hi Arlo

 

Please see below.

 

# Inserted By Customer Control Panel

SetENV PHPRC /home/mysitec/public_html

 

# ~~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>

RewriteEngine on

RewriteCond %{HTTP_HOST} !^mysite.com.au$

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

 

# Images

RewriteCond %{HTTP_HOST} ^mysite.com.au$

RewriteRule ^([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1-$2$3$4.jpg [L]

RewriteCond %{HTTP_HOST} ^mysite.com.au$

RewriteRule ^([0-9]+)\-([0-9]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1-$2$3.jpg [L]

RewriteCond %{HTTP_HOST} ^mysite.com.au$

RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]

RewriteCond %{HTTP_HOST} ^mysite.com.au$

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} ^mysite.com.au$

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} ^mysite.com.au$

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} ^mysite.com.au$

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} ^mysite.com.au$

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} ^mysite.com.au$

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} ^mysite.com.au$

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} ^mysite.com.au$

RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]

RewriteCond %{HTTP_HOST} ^mysite.com.au$

RewriteRule ^c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]

 

# Dispatcher

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteCond %{HTTP_HOST} ^mysite.com.au$

RewriteRule ^.*$ - [NC,L]

RewriteCond %{HTTP_HOST} ^mysite.com.au$

RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]

</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

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Hi All,

 

I am facing a similar issue with the re-directs when friendly-urls are turned on.

Some of the pages work properly but some don't and show the 404 page.

 

I edited the .htaccess file as suggested above but then the entire site goes down and shows a internal server error 500.

 

I deleted the following lines:

 

RewriteCond %{HTTP_HOST} ^www.leatherproductsindia.com$

RewriteRule . - [E=REWRITEBASE:/]

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

 

and replaced with:

RewriteCond %{HTTP_HOST} !^www.leatherproductsindia.com$

RewriteRule (.*) --URL::4e2674af6e4156e43e7b5163b4b5fbd0-- http://www.leatherproductsindia.com/$1 [R=301,L]

 

and I started getting the 500 error.

If I revert to the original some pages work some don't.

I am not sure if the 32 bit key (highlighted below) I am adding is correct in the following line:

RewriteRule (.*) --URL::4e2674af6e4156e43e7b5163b4b5fbd0-- http://www.leatherproductsindia.com/$1 [R=301,L]

 

How do I get this key??

Prestashop version: 1.5

Link to comment
Share on other sites

I solved the problem...

I disabled apache multiviews i.e. set the radio button to YES on the option "

Disable apache multiviews

"

 

I am using the original .htaccess that prestashop generates and didn't edit anything.

 

Thanks!

Link to comment
Share on other sites

Did anyone ever manage to get the Canonical URL v1.3 working properly? I'd really like to have the rel=canonical link in the source code and with v1.3 active I get double URLs (E.g. http://www.mysite.com/www.mysite.com).

 

I'm still using Prestashop 1.4.3 as I've had major issues trying to upgrade. I have the presto chango duplicate content module installed but still want the canonical reference in my site source code.

Link to comment
Share on other sites

  • 10 months later...

Hi guys!

 

To share my experience

 

I followed the step provided by Bill Dalton, and it worked out

 

My website was www.my-domain.com and i wanted to redirect all the traffic from my-domain.com to www.my-domain.com

 

I have the friendly url and the canonincal options enabled. The apache multiviews disabled

 

There is a small typing error in Bill answer:

RewriteCond %{HTTP_HOST} !^your-domain.com$

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

 

The ! has to be deleted right before the ^your-domain.com$

 

Here is the htaccess that worked for me:

 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.my-domain.com$
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^my-domain.com$
RewriteRule (.*) http://www.my-domain.com/$1 [R=301,L] 
 
You can see it working at ozapato.com or www.ozapato.com ;)
 
Best

 

 

  • Like 2
Link to comment
Share on other sites

×
×
  • Create New...