Friendly url does not accept bar after link

Asked

Viewed 276 times

1

I have in . htaccess the following code:

RewriteRule ^([a-z0-9-]+)/?$ categoria.php?key=$1 [NC,L]

It works perfectly, but when I put the bar after the link, it opens the page without CSS formatting, as if it were opening a new directory. Ex.:

Works:

www.site.com.br/clothes

Doesn’t work:

www.site.com.br/clothes/

How would I make you accept the bar at the end of the directory?

1 answer

1


If your link to the css is being looking relative to the file so:

 href="css/seu_arquivo.css"

And your files are in the root folder of the directory (probably httpdocs or something like that) so the search of the file path takes place as follows:

httpdocs/css/seu_arquivo.css

It turns out that when you add the bar, your file that 'linka' the css understands that you are inside a folder roupas/, soon he looks so:

httpdocs/roupas/css/seu_arquivo.css

To get around this there are two ways I know, one is by putting the absolute path with the url of your domain:

href="http://meudominio/css/seu_arquivo.css"

Or the best solution is to put the path up a level folder if your files are all in the root folder of your domain like this:

 href="../css/seu_arquivo.css"

Remembering that this goes for all file links (css/js) and in some cases on src of the images.

  • Hello Bruno. Actually the problem is in the user-friendly url within htaccess. Because the page that brings the information is the.php category and its css is usually picking up..

  • 1

    It just doesn’t work if you put the right bar?

  • I adjusted my post, I apologize for the misunderstanding.

  • 1

    KK just to understand why I got confused. URL does not open, or opens but only without css formatting?

  • The url opens normally when we do not put the bar, but when we do, it interprets as its a new directory

  • 1

    Tried to use my solution, or didn’t understand something.

  • I just tried and it worked. Really putting the absolute path worked. I will mark as correct answer. Thank you Bruno.

  • There’s still the tag base of html, I didn’t get to test but if you want to take a look, it seems interesting https://webdesign.tutsplus.com/articles/quick-tip-set-relative-urls-with-the-base-tag--cms-21399

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.