Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:53:39+00:00 2026-06-04T04:53:39+00:00

I am using MOD_REWRITE to channel all URLs through a single file. The aim

  • 0

I am using MOD_REWRITE to channel all URLs through a single file. The aim is to allow pretty urls like:

http://mysite.com/shop/electrical/hoover

or

http://mysite.com/shop/checkout

etc etc

I achieve this using the following .htaccess file:

# Turn on the RewriteEngine
RewriteEngine On
#
#  Rules
#
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . urlbug.htm

This is the stripped down HTML file that does all the work:

<!doctype html>
<html class="no-js" lang="en"> 
<head>
<meta charset="utf-8">
<title>My web page</title>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.20.custom.css" media="all"    rel="stylesheet"/>
</head>
<body>
<div id="accordion"><h3><a href="#">Home</a></h3><div>
<ul class="submenu"><li><a href="#" title="Clear Counters">Clear Counters</a></li></ul>
</div>
<h3><a href="#">Maintan Tables</a></h3>
<div>
<ul class="submenu">
<li><a href="#" title="Stock">Stock</a></li>
<li><a href="#" title="Categories">Categories</a></li>
<li><a href="#" title="Designers">Designers</a></li>
</ul>
</div>
<h3><a href="#">User Database</a></h3><div><ul class="submenu"></ul></div>
</div>
<script src="js/libs/jquery-1.7.1.min.js"></script>
<script src="js/libs/jquery-ui-1.8.20.custom.min.js"></script>
<script src="js/plugins.js"></script>
</body></html>

This works if you visit a URL like:

http://www.facebookanswers.co.uk/code/foobar/works

However, if you try a URL like:

http://www.facebookanswers.co.uk/code/foobar/no/longer/works

Then the URL will load, however, none of the CSS or JS files will load.

This is because I am using relative URLs.

If I instead use absolute URLs, then all works fine. I have set up a different folder to demonstrate this:

http://www.facebookanswers.co.uk/code/foobar2/works

and

http://www.facebookanswers.co.uk/code/foobar2/works/as/well

This is the code with the absolute URLs:

<!doctype html>
<html class="no-js" lang="en"> 
<head>
<meta charset="utf-8">
<title>My web page</title>
<link type="text/css" href="http://www.facebookanswers.co.uk/code/foobar2/css/ui-lightness/jquery-ui-1.8.20.custom.css" media="all" rel="stylesheet"/>
</head>
<body>
<div id="accordion"><h3><a href="#">Home</a></h3><div>
<ul class="submenu"><li><a href="#" title="Clear Counters">Clear Counters</a></li></ul>
</div>
<h3><a href="#">Maintan Tables</a></h3>
<div>
<ul class="submenu">
<li><a href="#" title="Stock">Stock</a></li>
<li><a href="#" title="Categories">Categories</a></li>
<li><a href="#" title="Designers">Designers</a></li>
</ul>
</div>
<h3><a href="#">User Database</a></h3><div><ul class="submenu"></ul></div>
</div>
<script src="http://www.facebookanswers.co.uk/code/foobar2/js/libs/jquery-1.7.1.min.js"></script>
<script src="http://www.facebookanswers.co.uk/code/foobar2/js/libs/jquery-ui-1.8.20.custom.min.js"></script>
<script src="http://www.facebookanswers.co.uk/code/foobar2/js/plugins.js"></script>
</body>
</html>

Somewhere along the line, the path is getting confused. What is the best way around this? I would like to keep relative URLs if possible, as the code I am developing will be used on a number of sites. Its not the end of the world if I have to use absolute URLs, and I know that there are performance benefits in absolute URLs, but it seems odd that the browser will happily load the URL, but then think that it is stored somewhere else!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:53:40+00:00Added an answer on June 4, 2026 at 4:53 am

    Use root relative URLs.

    The problem is that the browser sees a URL like http://www.facebookanswers.co.uk/code/foobar/no/longer/works so a relative link would resolve as http://www.facebookanswers.co.uk/code/foobar/no/longer/works/code/foobar2/css… and so on.

    Instead use this…

    <link type="text/css" href="/code/foobar2/css/ui-lightness/jquery-ui-1.8.20.custom.css" media="all" rel="stylesheet"/>
    

    By starting with a / you’re forcing it to be relative to the root of the website, but by not specifying the domain, it’ll work just fine if you deploy on another site. This is really just an HTML issue rather than a mod-rewrite one.

    Take a look at your server access logs and you’ll see what pages are being requested, and you’ll see they’re not what you were expecting.

    Site-wide resources are always best referred to with root-relative URLs – it means you don’t need to adjust them based on where you are in the site, and it makes them portable between sites (which is handy if, like me you have your development site on a local machine with a different domain name – I use http://www.example.com.dev when working locally on http://www.example.com)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to change all http://www.mysite.com/filename.php files to show as http://www.mysite.com/filename/ using mod_rewrite, but
I'm using mod_rewrite to redirect on URLs like: mysite.com/123 RewriteEngine On RewriteRule ^([0-9]+)$ /n/index.php?id=$1
I'm using mod_rewrite to change all the URLs on a site. Example: http://www.site.com/about/ becomes
I'd like to redirect all top level directories to a file using mod_rewrite. So
Hay, I'm using mod_rewrite with apache, and want URLS from http://www.DOMAN.com/course/course-a/ to actually serve
Using mod_rewrite, how could I turn URLs that follow this pattern: http://example.com/index.php?id=14 Into this
I've been using mod_rewrite in my htaccess file to rewrite my urls and I've
I'm using mod_rewrite to rewrite pretty URLs to a form supported by a Spring
I have an .htaccess file using mod_rewrite to redirect URLs from the old website
I want to redirect the following url: http://abc.com/colleges/first.php to http://abc.com/first.php using mod_rewrite and .htaccess

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.