简体   繁体   中英

Fishpig Wordpress Magento - http://example.com/blog resolves to www.example.com rather than www.example.com/blog

I have a working Fishpig Wordpress Magento instance on a production server.

All the green ticks show it has succesfully configured and when visiting

http://www.example.com/blog 

it works. However when I try and and visit

http://example.com/blog 

it sends me back to the magento home page at www.example.com .

I have tried setting the url in wordpress to both http://example.com/blog and http://www.example.com/blog but in both situations it always sends me to the home page at site.com.

This is a concern because most experienced web users will not type www when trying to access a location.

My htaccess is as generated by Wordpress and looks like

DirectoryIndex index.html index.php

<IfModule mod_rewrite.c>

#wp generated
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Please not the wordpress site files are located at site.com/wp and it is the fishpig extension which arranges the direct from the non existent /blog path.

First of all, to start of, one way to resolve the issue is to simply make your Magento website DEFAULT to not have the www. in the url.

In Magento, go to System > Configuration > Web.

In the "Secure" and "Unsecure" tabs, find "Base URL."

The value should look something like this:

http://www.site.com/

Replace ALL references to the domain so it shows:

http://site.com/

Unfortunately, there may be a lot of appearances of it throughout the site. You'll need to do the same thing elsewhere on the server.

If you really want your site/blog to say www., though, you'll have to properly forward the .htaccess file in Magento. I'm not too keen on how Magento's .htaccess file works, but I do know how to forward a url and keep all of its additional pages as well (however, Magento's setup may interfere).

The code should look something like this:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^site.com$ [NC,OR]
RewriteRule ^(.*)$ http://www.site.com$1 [R=301,L]

Again, I don't know how well this will work with Magento's set up, but I've successfully used the above code to redirect url's to the correct url I want. That code above was actually used on a wordpress site, though.

Check for Rewrite rules in Magento's .htaccess file and try putting this above it. Be careful, though; it is VERY easy to cause 500 internal server errors if you mess up the .htaccess file, so always keep a backup.

Try this out and I hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM