XpertWorlock Posted June 23, 2010 Share Posted June 23, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/ Share on other sites More sharing options...
cags Posted June 23, 2010 Share Posted June 23, 2010 Yes, all resources will need to be relative to root (i.e. absolute). Obviously you also need to make sure your REGEX patterns don't match the name of the css/js/img files. Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/#findComment-1076015 Share on other sites More sharing options...
XpertWorlock Posted June 24, 2010 Author Share Posted June 24, 2010 you say absolute and than relative? you mean the full absolute url in each css file like http://whatever.com/css/stylesheet.css ? Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/#findComment-1076808 Share on other sites More sharing options...
cags Posted June 24, 2010 Share Posted June 24, 2010 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'. Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/#findComment-1076816 Share on other sites More sharing options...
XpertWorlock Posted June 26, 2010 Author Share Posted June 26, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/#findComment-1077549 Share on other sites More sharing options...
cags Posted June 26, 2010 Share Posted June 26, 2010 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"/> Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/#findComment-1077563 Share on other sites More sharing options...
XpertWorlock Posted June 29, 2010 Author Share Posted June 29, 2010 -SNIP- I got it, thanks for your help cags Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/#findComment-1078499 Share on other sites More sharing options...
XpertWorlock Posted June 29, 2010 Author Share Posted June 29, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/#findComment-1078501 Share on other sites More sharing options...
cags Posted June 29, 2010 Share Posted June 29, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/#findComment-1078582 Share on other sites More sharing options...
XpertWorlock Posted June 29, 2010 Author Share Posted June 29, 2010 thanks cags Quote Link to comment https://forums.phpfreaks.com/topic/205609-rewrite-404-for-files/#findComment-1078727 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.