InsaneCoder
InsaneCoder

Reputation: 8278

htaccess : Getting incorrect reference paths

I have following directory structure

server_root/Project1/(all_files_including_.htaccess)

I have written following rule

RewriteRule ^cost-calculator/([a-z]+)/$ cost-calculator.php?in=$1

for page

cost-calculator.php?in=seattle

Firstly, page doesn't work until I add / at the end of URL. Secondly, its not loading js,css files. The path being generated for these files are like cost-calculator/seattle/js/jquery.min.js. Why cost-calculator/seattle is prefixed for the css/, js/ files?

What's wrong?

Upvotes: 0

Views: 101

Answers (2)

Bhavesh G
Bhavesh G

Reputation: 3028

Always consider to use absolute path (/the/file/path or full address eg. http://the/file/path). Don't be lazy and change your relative URIs in your resources. This is the best.

Refer the answered questions here, URL rewriting : css, js, and images not loading

Upvotes: 1

David Duponchel
David Duponchel

Reputation: 4069

For the first question : you have a trailing slash in your RewriteRule, it will only match if there is a trailing slash in your url. Try an interrogation mark to set the slash as optional : ([a-z]+)/?$

For your second question : it seems like the page includes "js/jquery.min.js". This url is relative to the current page and the full path is resolved by the browser. When you are on "/cost-calculator/seattle/", the full path will be "/cost-calculator/seattle/js/jquery.min.js". The easiest fix is to give the full path for your css/js resources : src="/full/path/to/js/jquery.min.js"

Upvotes: 1

Related Questions