Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a simple web app and I set it up to use .htaccess for rewrite rules.

Options +followSymlinks
RewriteEngine on
Rewriterule ^records/view/([0-9]+)$ ./record_view.php?id=$1 [NC]

It works but the page doesn't see the external CSS file. Instead of looking for ./style.css, it's looking for records/view/style.css.

<link rel="StyleSheet" href="style.css" type="text/css" />

It works if I use the full path to it: href="/myapp/style.css".

The app was written before the rewrite rules were added, so this breaks all the links in the app too. href="index.php" has to become href="/myapp/index.php".

Do I have to go back and fix all the links just to use rewrite rules or is there a configuration I can change? (Ubuntu Server 11, Apache2, PHP5)


share|improve this question
up vote 1 down vote accepted

How about catching all of the requests for resources, and rewriting them back to how they need to be?

# Existing config:
RewriteEngine on
RewriteRule ^records/view/([0-9]+)$ ./record_view.php?id=$1 [NC]
# Add:
RewriteRule ^records/view/(.*)$ ./$1 [NC]

That fixes resources, but doesn't help with links - those would need to be redirects.

You could, of course, work around that with more rules, but I'd recommend fixing the links. Cleaning up your HTML to work with your application's structure makes more sense than hacking around it in Apache's config.

share|improve this answer
This rule helps alot. Like you said, I'll still have to fix the hard coded links, but that's kind of the reason I'm rewriting the URLs in the first place. Thanks! – Ed Manet Apr 9 '12 at 19:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.