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 7772497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:54:16+00:00 2026-06-01T16:54:16+00:00

Background Trying to recreate StackOverflow-style pretty URLs using Apache’s mod rewrite and PHP. Problem

  • 0

Background

Trying to recreate StackOverflow-style pretty URLs using Apache’s mod rewrite and PHP.

Problem

This works great:

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteRule ([0-9]+)$ index.php?id=$1 [L]
</IfModule>

URLs like http://localhost/home/script/5 redirect to http://localhost/home/script/index.php?r=5. The CSS content loads flawlessly.

URLs like http://24.68.226.186/recipes/recipe/5/seo-text redirect, but the relative path for the CSS files is then incorrect:

<link rel="StyleSheet" hreF="css/theme.css" type="text/css" media="screen,print" id="css-theme" />

Directories

The directory structure for the script (index.php) resembles:

htdocs/home/script
htdocs/home/script/.htaccess
htdocs/home/script/index.php
htdocs/home/script/css
htdocs/home/script/images

Question

How do you use mod rewrite to tell Apache to use the “script” directory when serving files instead of any sub-directory appended to the URL?

In other words, how would you use mod rewrite to lop off the “seo-text” part of the URL and (1) ensure it reflects the actual title [sourced from a database]; (2) redirect the browser to the new URL [if necessary]; and (3) tell Apache to ignore all paths beyond the ID in the URL?

I would rather not use absolute paths in the CSS.

Thank you!

  • 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-01T16:54:17+00:00Added an answer on June 1, 2026 at 4:54 pm

    Used Logan’s advice:

    <base href="/home/script/" target="_self" />
    

    This does not work with IE8, due to a bug.

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

Sidebar

Related Questions

Background I am trying to include an rss feed using php into a html
Background: I'm trying to write a shell script using php that will automatically checkout
Background: I'm trying to come up with a regex for a rewrite rule that
Trying to create a background-image slideshow and am getting this error... This is the
I'm trying to recreate the look of a UINavigationBar. The background of the bar
I have a strong background in PHP / ZEND and I'm now using learning
Background Trying to switch from using Interceptor to Events. I have a ValidationInterceptor that
Background: I am trying to animate a rotating 3D scatter plot using R's lattice::cloud()
Resolution: While trying to recreate this bug in a fresh project to submit to
I have a problem in that I am trying to background load a sound

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.