Jump to content

URL rewriting adds another page/


kartul

Recommended Posts

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.