J.Doe J.Doe - 1 month ago 7
Apache Configuration Question

.htaccess requires extra '../' on src files

I am trying to turn

Topics?t=a


Into

Topics/a


For that purpose i wrote this htaccess code

RewriteRule ^Topics/([0-9a-zA-Z]+) Topics.php?t=$1 [NC,L]


And now when url is
Topics/a
it requires extra '../' on src files like css or javascript.

Answer

Requirement to add an extra ../ is due to the fact that you're using relative paths in your css/js/images.

The new pretty URL in use is this:

Topics/a

If you're including css as href=style.css then it will try to find it as /Topics/style.css.

When using ../ it will correctly find css as /Topics/../style.css that translates to /style.css.

Note that instead of ../ you can add a / before your relative path to make it as:

href=/style.css

Alternatively You can add this just below <head> section of your page's HTML:

<base href="/" />

so that every relative URL is resolved from that base URL and not from the current page's URL.