jk11uk Posted May 30, 2008 Share Posted May 30, 2008 ive rewritten my urls so that: site.com/section/index.php?subsection=X&article=Y becomes site.com/section/subsection/article.html but now it seems to think that subsection is an actual folder and has thrown out all my '../filename' links. So it doesn't find the CSS or images anymore. i was using ../ so that it looked one folder below for the files, it now thinks the files are 2 folders below (because of the rewrite) Does anyone know how to solve this? i can just put the root address in because i'm using a staging server for now and don't want to have to go round changing all the URLs before launch thanks Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/ Share on other sites More sharing options...
MadTechie Posted May 30, 2008 Share Posted May 30, 2008 can you post the rewrite Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-553485 Share on other sites More sharing options...
jk11uk Posted May 30, 2008 Author Share Posted May 30, 2008 RewriteEngine On RewriteRule ^([^/]*)/$ /section/index.php?category=$1 [L] RewriteRule ^([^/]*)/([^/]*)-([^/]*)\.html$ /section/index.php?category=$1&url=$2&id=$3 [L] the rewrite works fine. problem is it causes the folder to be seen as one deeper than it physically is, so ../doesn't work anymore. Also, using ../../ instead would mean that the article level wouldn't work even if category level was finding the files Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-553490 Share on other sites More sharing options...
MadTechie Posted May 30, 2008 Share Posted May 30, 2008 you may get away with something as simple as this change RewriteRule ^([^/]*)/$ /section/index.php?category=$1 [L] to RewriteRule ^([^//.]*)/$ /section/index.php?category=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-553499 Share on other sites More sharing options...
jk11uk Posted May 30, 2008 Author Share Posted May 30, 2008 what does the extra /. mean? the rewrite works perfectly, my problem is that it creates 'virtual folders' and this extra folder deptch means the way i reference image/php file includes /css includes etc doesn't work properly. i use ../ which looks one depth below, but the /section/ created means ../ only looks in the same directory as the .index.php file is hard to explain, do you get me? Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-553544 Share on other sites More sharing options...
MadTechie Posted May 30, 2008 Share Posted May 30, 2008 basically ^[^//.] means don't start with / or . so /test or ../test will not be used by the rewrite.. can you post some links that are NOT working anymore.. as the only things that should be affected are things that end with a / or .html, so hello/world.jpg would work fine. Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-553549 Share on other sites More sharing options...
beboo002 Posted May 31, 2008 Share Posted May 31, 2008 This problem is called absolute path problem Here u make two rule for same page in your. htaccess file for rewrite url this is your main problem for not getting absolute path Any way I have an idea If(($_GET[‘category’]!=””)&& ($_GET[‘&url’]!==””)) { $link=”../../”; } else { $link=”../”; } Put $link like <link rel="stylesheet" href = "<?=$link?>css/cascading.css" type="text/css"> Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-554034 Share on other sites More sharing options...
jk11uk Posted June 3, 2008 Author Share Posted June 3, 2008 ah good idea, that works fine thanks. Although, for another section i have rewritten the URLs in pretty much the same way with: RewriteEngine On RewriteRule ^([^-]*)-([^-]*)\.html$ /section/article.php?url=$1&id=$2 [L] so it should go: /section/articlename-id.html This normally works fine for me, but now if i have any hyphens in the url value, it makes an error because it expects the id. So the following wont work: /section/article-name-id.html any ideas? Can you 'ignore' certain characters? Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-556301 Share on other sites More sharing options...
jk11uk Posted June 3, 2008 Author Share Posted June 3, 2008 ^([^/]*)-([^/]*)\.html$ solved it, just needed that code. Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-556304 Share on other sites More sharing options...
beboo002 Posted June 3, 2008 Share Posted June 3, 2008 Test this one ^article-(.+)-([0-9]+)\.html$ /section/article.php?id=$1&j=$2 [L] Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-556336 Share on other sites More sharing options...
samshel Posted June 3, 2008 Share Posted June 3, 2008 Just a suggestion: For CSS and Images in case URL rewritten sites, I personally would use Absolute paths, doesnt make a difference in speed as well as doesnt make a difference from which directory you call them Ignore post, if you feel it is not important. but it helps me a lot. Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-556406 Share on other sites More sharing options...
beboo002 Posted June 4, 2008 Share Posted June 4, 2008 its matter when u make fully Dynamic site like http://huntor.org its make only one page site each time when go subfolder then page url change like http://www.huntor.org/Travel-154-1.html Then go inner directory http://www.huntor.org/Travel/Apartments-507-1.html I have make only one rule in .htaccess file Each time when go sub directory number of forward sleaes “/” increase here ur absolute path make problem because php count it as subfolder but u set ur path(css,images) as main folder. Quote Link to comment https://forums.phpfreaks.com/topic/107983-url-rewriting/#findComment-557159 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.