Jump to content

Recommended Posts

Question, when doing a mod rewrite when it comes to long urls lets say for example ;

 

test.php?id=1

 

to

 

test/1

 

Now, all the files (css, js) are looking for them in the "1" directory which obviously does not exist.  I have listed everything as relative.

 

Is the fix for this to link everything absolute?

Link to comment
https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/
Share on other sites

I said absolute, then 'relative to root'. They essentially mean the same thing. If 'style.css' is in a folder called 'css', which is in the root directory, then it's path relative to root is '/css/style.css' which should references the exact same location as 'http://domain/css/style.css'.

I know what you mean, and I must be missing something, perhaps from the .htaccess file

 

The link to the css file in the test file, which is in the root directory:

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

 

So naturally searching

 

test.php?id=1

 

would work fine, but since it's being changed to

 

test/1

 

it isn't...  Sorry to repeat myself, but better more info than less.  Here is what the .htaccess file is.

 

Options +FollowSymLinks   
RewriteEngine On   
  
RewriteRule ^test/([0-9]+)/?$ test.php?id=$1 [NC]

 

Correct?

The rule is right, but the location of your script isn't, you haven't made it relative to root, it is relative to 'current directory', which because of the rewrite is '1'.

 

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

My problem was with WAMP.

 

A separate directory for a project was causing your '/' to look in the 'localhost' directory.

 

Is there any easy way of having it work both on a site and offline?

 

Example project being http://localhost/testProject

 

Looks for CSS or whatever in localhost directory and not testProject, or am I required to load everything straight into the localhost folder?

You'll need to set-up a 'proper' localhost set-up, by creating a vhost for each project you do.

 

I wrote/recorded this awhile ago before I knew a great deal about Apache configuration, but it get's the main points across...

http://phpacademy.info/forum/viewtopic.php?f=31&t=911

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.