kartul Posted August 13, 2010 Share Posted August 13, 2010 Hello everyone I got little problem with URL rewriting and styles, js files and pictures. Current code I have: Options +FollowSymlinks RewriteEngine On RewriteBase /test RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule index index.php [NC] #just index, no file ext. RewriteRule page/(.*) index.php?page=$1 [QSA,NC,L] # should display myhost.com/test/page/13 Now the problem is, the first rule works, entering just index without ext. works. But the second rule works fine first time (myhost.com/test/page/2) but next page, it adds another page/ to the url (myhost.com/test/page/page/3) and browser displays error that the links is expired. when I change the last rule to: RewriteRule page/[(0-9)+] index.php?page=$1 [QSA,NC,L] the index.php?page=13 doesn't get there - I tried to echo it out and it was empty. I'm stuck now cause the QSA flag is there and it should add this new number, i.e 13 there. Quote Link to comment https://forums.phpfreaks.com/topic/210627-url-rewriting-adds-another-page/ Share on other sites More sharing options...
cags Posted August 13, 2010 Share Posted August 13, 2010 The problem is with your HTML not your rewrites. You almost certainly have something along the lines of... <script type="text/javascript" src="js/cool_mojo.js"></script> Despite the fact you have rewritten the file on the server side, the client has no way of knowing this. All the browser knows is that it it requested '/page/something', so when it encounters a path of 'js/cool_mojo.js', it thinks the path is '/page/js/cool_mojo.js'. The solution to your problem is to simply use paths relative to the root '/' a.k.a absolute paths. <script type="text/javascript" src="/js/cool_mojo.js"></script> Quote Link to comment https://forums.phpfreaks.com/topic/210627-url-rewriting-adds-another-page/#findComment-1098814 Share on other sites More sharing options...
kartul Posted August 13, 2010 Author Share Posted August 13, 2010 Damit! I had a problem and I solved it but got another problem. Now both problems are there. Damit, my mistake. I have the styles, js and images fixed. I added the full url there. They work now fine. The real problem what I'm now facing is the pagination (content split between pages) urls. Currently I have following line: RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [QSA,NC,L] The pagination works, content get's splited up between pages but the url is messed up. first page get's served as myhost.com/test/page/2, next url is myhost.com/test/page/page/3 (it works tho, right content is shown), next one again, one more page there (myhost.com/test/page/page/page/3). if I go back, it still adds another page/ there. Now, my question is, how can I get rid of the page/'s there and only show one? Again, I apologies for the wrong info in first post. Quote Link to comment https://forums.phpfreaks.com/topic/210627-url-rewriting-adds-another-page/#findComment-1098817 Share on other sites More sharing options...
cags Posted August 13, 2010 Share Posted August 13, 2010 Sounds like essentially the same problem/solution as before, it sounds like you are echo'ing out a href with a path of 'page/something', any path that is interpreted on the client side needs to be absolute. Quote Link to comment https://forums.phpfreaks.com/topic/210627-url-rewriting-adds-another-page/#findComment-1098885 Share on other sites More sharing options...
kartul Posted August 13, 2010 Author Share Posted August 13, 2010 WOW. I added /test/ into my pagination script and it all works perfect! Thank You so much.!! Quote Link to comment https://forums.phpfreaks.com/topic/210627-url-rewriting-adds-another-page/#findComment-1098889 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.