1

i am using a Rewrite rule for my site but its changing changing script src Path

here is the rule i am using

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ /user_page.php?id=$1 [NC]

# Changing Search URL
RewriteRule ^/([^/]*)/([^/]*)/([^/]*)$ search_out.php?comp_city=$1&one=$2comp_landmark=$3 [L]

# Changing Search URL is the one which is causing prob ... page it will show u the script src or all link rel="stylesheet" type="text/css" are pointed to http://www.xxxxx.com/Rajpura/Schools/js/jquery-1.6.2.min.js rather than http://www.xxxxx.com/js/jquery-1.6.2.min.js

Please help

2 Answers 2

2

You can add the base tag to the head tag in each of your pages :

<base href="/">

This way, the browser will prepend all the links in that page by /.

For more informations about the base tag, see documentation

Sign up to request clarification or add additional context in comments.

1 Comment

How is this different from what is said?
0

And when embedding CSS or images in your html, try to begin with a slash to get the files from the root directory:

<link rel="stylesheet" href="/css/style.css" />

The same with images:

<img src="/images/pic.png" alt="image" />
<img src="/mypic.png" alt="image" />

Or a Workaround would be is to add this in your template :

<base href="/">

This will force browsers to prepend the / (in this example) to all relative resource links.

5 Comments

Thx But is there any other way out ?? by doing changes in .htaccess... thx
no RewriteBase will not work (because it is not like that how it works). you can write a rule to redirect anything that contains (for example) js/ to /js/, but I don't suggest you to do that, the best way is adding the <base href="/" /> tag to your pages
@Yazmat Thx But almost all my links are src=".. not src="/ so is there any other way i can do that ?? if possible ...
@Harinder : you add the base tag only once per page in the head tag, not for every src or href
@Yazmat Thx Man it worked ... can you make it an answer so i can accept and close the question ....;)

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.