0

Currently i have this store files structure:

www.mysite.com/store as the index for the store (store.php) (already working without .php) where i have all the items listed

Then i have the subcategories file as subcategories.php

Finally my products file product_detail.php

This is what i have done so far:

RewriteCond %{THE_REQUEST} /subcategories\.php\?subcatid=([a-zA-Z0-9_-]+) [NC]
RewriteRule ^/store/%1? [R=302,L,NE]
RewriteRule ^store/([a-zA-Z0-9_-]+)/?$ subcategories.php?subcatid=$1 [L,QSA,NC]

And made a php script to change the id for the name in the url following this code:

if(isset($_GET['subcatid'])){
    if(is_numeric($_GET['subcatid'])){ //Check if the input is all numeric
        //Grab the username from database
        //Redirect user to site.com/user/$username
    }
}

So, i final example is like www.mysite.com/store/furniture <- subcatid

Where is listing all the the products from that subcategory.

It's loading ok but styles and js are missing, how can i correct this and what approach should i take to each subcategory product with htaccess?

1 Answer 1

1

Add this at the top of your html in the head section

<base href="http://www.example.com/store/" />

Replace with your site. This is providing your assets are in a sub directory of store otherwise if the assets is in a directory in the root use this.

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

2 Comments

Is there any other way with htaccess to do it?
I don't get why people try to do everything with .htaccess. It's trying to use the relative path because of the rewrites. It's not an htaccess problem. You either need to use / at the beginning your of your paths, e.g. /path/to/style.css, use absolute paths for your assets or the base tag. All of which is something you control in your html.

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.