0

I have a .htaccess file with the following:

RewriteEngine On
RewriteRule   ^product/(.+)$   /product.php?name=$1   [L]

This basically looks for "product/" within the URL and redirects to product.php

product.php is in the root folder: eg. mywebsite.com/product.php and when loaded directly looks fine and all CSS works.

However when I go to mywebsite.com/product/example-product the redirect to product.php works, but the CSS is lost (It's in a seperate stylesheet).

I do not have a product directory, is this why the CSS won't load? Is it possible to have directories in the URL yet redirect to a file in the root folder?

Ideally, I'd like the following:

mywebsite.com/product/example-product

redirects to

mywebsite.com/product.php?name=example-product

I hope that makes sense.

3
  • Just set a <base> that should fix it i think Commented Mar 5, 2015 at 9:36
  • 1
    Perfect! I thought it would be more complicated than that, it worked a charm. Thanks!! Commented Mar 5, 2015 at 9:41
  • No problem at all. I'll add it as an actual answer too :) Commented Mar 5, 2015 at 9:57

1 Answer 1

1

All you need to do is set a base tag in your HTML head. For example:

<base href="http://www.website-example.com">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.