Htaccess, redirect but keep url

Hi

I have built a shop on a different domain and would like to include this on my website without changing the url.

I followed a tutorial online which was titled:
Visitors can access your site using your domain, but see the content of an external URL.

This is my code in the .htaccess file. but nothing happens:


RewriteCond %{HTTP_HOST} ^mywebsite.com/shop
RewriteRule ^(.*) http://www.shopwebsite.com/shop [P]

Thanks

You’re missing RewriteEngine On

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mywebsite.com/shop
RewriteRule ^(.*) http://www.shopwebsite.com/shop [P]

Sorry RewriteEngine On was already in the .htaccess file so I didn’t mention it in the post.

Any ideas why its not working?

Silly question, but you are sure your server is running Apache?

Yep the server is running Apache :slight_smile:

Here is the full code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mywebsite.com/shop
RewriteRule ^(.*) http://www.shopwebsite.com/shop [P]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

D’oh, /shop is not part of the HTTP_HOST, I don’t know why I missed that before :confused:

You should change it to this:

RewriteCond %{HTTP_HOST} ^mywebsite\.com$
RewriteRule ^/shop http://www.shopwebsite.com/shop [P]

Hi ScallioXTX

Really appreciate you getting back to me! But it still hasn’t worked :frowning:
Nothing happens when I go to mywebsite.com/shop. I’ve emptied cached and refreshed browser. Tried on a different browser etc… but still nothing!
All my other redirects are working (I have a few 301 redirects) but I can’t get this to work :cry:

Do you have any alternative ideas of how to include the shop on my website without revealing the real url of the shop? I’ve tried iframe, but it doesn’t display content from my account and the checkout! at which point I get the following error:
[Error] Refused to display in a frame because it set ‘X-Frame-Options’ to ‘SAMEORIGIN’.

Any suggestions will be greatly appreciated! Many thanks again!

Can you post one of your other 301 redirects?

Redirect 301 /skin-health /health/skin

That would work for this one as well

Redirect 301 /shop http://www.shopwebsite.com/shop

Won’t that redirect to the site? I won’t want the url changing…

If you’re wanting to somehow “spoof” a users address bar, I’m afraid you’re pretty much out of luck.

AFAIK htaccess is good at allowing alternate URLs to work. eg.

^pretty_url$ https://example.com/real_but_ugly_url.php

Both example.com/pretty_url and example.com/real_but_ugly_url.php will still request the same file. The difference being that “pretty_url” can be used in links.

I think if you want to retain “pretty_url” displaying in users address bars the way to go is not with htaccess but with server side routing.

Browser security measures are in place so that “where the address bar says it is, is really where it is”

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.