Faisal
Faisal

Reputation: 21

.htaccess rewriting - URLs with multi level directories

I have a page deals.php which is placed at root directory that is being accessed by number of internal URLs with multi directory levels. for example this page would be accessed by both following urls.

http://domain/flights/asia/bangkok
http://domain/flights/bangkok

I am using this code in .htaccess to redirect to deals.php

    Options +FollowSymlinks
    RewriteEngine on

    RewriteRule ^flights/asia/([^/]+)/?$ deals.php?country=$1 [NC]
    RewriteRule ^flights/([^/]+)/?$ deals.php?country=$1 [NC]

Now the problem here coming is that on deals.php all the images, script and style sheet files are not opening properly. If I try to fix it against one URL by placing ../../ in addresses of all images, script and css, it dont work for other URL.

How to solve this problem? what are the options?

Upvotes: 1

Views: 963

Answers (2)

Pengfei.X
Pengfei.X

Reputation: 681

i think what you want is placing an baseurl in html page, so all the relative path will related to the baseurl, not the current URL in the navigator bar

Upvotes: 0

LazyOne
LazyOne

Reputation: 165088

Easy: DO NOT use ../ in links to any resources (images/css/js/etc) -- always use URL that is relative to the WEBSITE ROOT -- that is a "requirement" when you dealing with nice/not-real/rewritten URLs as such URL rarely points to the physical file location.

Lets assume you have a logo that is located at http://www.example.com/images/logo.png.

Now, instead of ../images/logo.png and/or ../../images/logo.png ALWAYS use /images/logo.png.

Upvotes: 1

Related Questions