Jump to content

Recommended Posts

So here is my structure:

 

public_html

  /site -> production site

  /v2 -> testing site

 

I've added a .htaccess file to the v2 directory to play with rewriting the urls.

 

I want www.test.com/v2/models/ab/75 to be the URL and for it to actually display www.test.com/v2/index.php?req=prod&cat=ab&model=75

 

I'm using the following rule in the .htaccess file at the v2 level:

 

RewriteRule ^models/([a-z]+)/([0-9]+)$ v2/index.php?req=prod&cat=$1&model=$2 [NC,L]

 

It works, and loads the page, and the URL stays as I would like, but all of my CSS/JS/ and images do not load because they all use relative paths.  Any ideas how I can get around that?

Link to comment
https://forums.phpfreaks.com/topic/194177-rewrite-causing-ignore-of-cssjs/
Share on other sites

Hey Ober,

 

Long time no see :)

 

Anyways, something like this *might* work:

RewriteCond %{REQUEST_FILENAME} !^.*\.css$

RewriteCond %{REQUEST_FILENAME} !^.*\.jpg$

 

I pulled it from a htaccess, so apologies if it doesn't work, but it might give you an idea.

 

-steve

<link rel="stylesheet" href="style/DefaultNew.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="style/Print.css" type="text/css" media="print">
<link rel="stylesheet" href="style/CSS.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="style/search.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="style/home.css" type="text/css" media="screen, projection">
<link rel="stylesheet" href="style/200803.css" type="text/css" media="screen, projection, print">
<link rel="stylesheet" href="style/200811.css" type="text/css" media="screen, projection, print">

<script type="text/javascript" src="libs/jquery-1.js"></script>
<script type="text/javascript" src="libs/Default.js"></script>
<script type="text/javascript" src="libs/swfobject.js"></script>
<script type="text/javascript" src="libs/__utm.js"></script><script language="JavaScript1.5">_ujv='1.5';</script>
<script type="text/javascript" src="libs/redesign.js"></script>

To put it bluntly, don't use relative paths. (I could explain at length that that is the solution, with pretty examples and such but it wouldn't really say anything other than that.)

So then I have to change every path in every file when I move everything to the final (production) location?  No thanks.  I'd rather deal with the 'less than pretty' URLs.

Hey Ober,

 

Long time no see :)

 

Anyways, something like this *might* work:

RewriteCond %{REQUEST_FILENAME} !^.*\.css$

RewriteCond %{REQUEST_FILENAME} !^.*\.jpg$

 

I pulled it from a htaccess, so apologies if it doesn't work, but it might give you an idea.

 

-steve

Good to see you too Steve.  Yeah, been too busy to hit this place up lately.  I'll give that a whirl.

To put it bluntly, don't use relative paths. (I could explain at length that that is the solution, with pretty examples and such but it wouldn't really say anything other than that.)

Thinking about this further, I guess I could use PHP to dynamically build the absolute path.  Just seems like a hassle.

I believe the problem is not that the .css file path itself is being redirected, it's rather that when the page that's been redirected attempts to fetch the a file, it tries relative to it's REQUEST_URL, not relative to it's actual position.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.