Jump to content

Recommended Posts

I have the following rewrite rule in place:-

 

RewriteRule ^Popular\.html$ index.php?getbypopular=1

 

However I have added some pagination to that page which I also want to rewrite

 

Popular.html/Page1

 

to

 

index.php?getbypopular=1&page=1

 

or whatever page it is

 

can anyone please help me out with this?

Link to comment
https://forums.phpfreaks.com/topic/223393-mod-rewrite-with-multiple-conditions/
Share on other sites

Thanks for the help David

 

It still appears it's not working though.

 

The page I'm using the link from is this:-

 

http://www.mytestsite.com/myshopsite/myproducts.co.uk/Popular.html

 

I have a link on that page that goes to i.e. it's href is:-

 

/myshopsite/myproducts.co.uk/Popular.html/Page$pagenum

 

with $pagenum being the page number in question

 

If the page 2 link is clicked for example it goes to this page:-

 

http://www.mytestsite.com/myshopsite/myproducts.co.uk/Popular.html/Page2

 

but the problem is I'm getting a 404 - not found message on that page

 

However if I type into the url bar:-

 

http://www.mytestsite.com/myshopsite/myproducts.co.uk/index.php?getbypopular=1&page=2

 

It works as it should.

 

It's totally confusing  :confused:

 

Is this a mistake in the rewrite rule/file?

As I said, I'm no expert at rewrite. I'm not really sure what regexp constructs are allowed in it. You might try changing it to this:

RewriteRule ^Popular\.html/Page([0-9]*)$ index.php?getbypopular=1&page=$1

just in case the "\d" construct is not allowed.

 

Note: you could add a custom error page using something like this in the .htaccess

	ErrorDocument 404 /err404.php

 

Then write the err404.php file to just dump $_SERVER to the screen

<?php
echo '<PRE>';
print_r($_SERVER);

 

So you can see what the request looks like. It might help you to debug this.

 

Note: Do NOT do this on a production server, it could show information you don't want visible to hackers. If you absolutely have to put it in production, remove the file and directive as soon as you get the results.

 

If you have access to the main http.conf file, you can turn on rewrite logging. This dumps ALOT of information about the rewrite process to a log file. It cannot be set in the .htaccess file (at least not to my knowledge) and should not be left on in production because it slows things down and it dumps ALOT of information into log files. 

 

Did I mention that the rewrite logging will write ALOT of stuff to log files using up large amounts of disk space?

Hi David. That new rule seems to work fine i.e. all of the information for the selected page shows up however it's strange because in the pages pages themselves it seems all css is removed.  :confused:

 

I think it may be a problem with the links in my site itself.

 

Let me explain. The first page of my site is:-

 

http://www.mytestsite.com/myshopsite/myproducts.co.uk/

 

I have a few links across the top of that page. One of the links goes to the popular page and it's href is:-

 

Popular.html

 

I already have a rewrite rule in place for this which works:-

 

RewriteRule ^Popular\.html$ index.php?getbypopular=1

 

So the popular page looks like this:-

 

http://www.mytestsite.com/myshopsite/myproducts.co.uk/Popular.html

 

I have pagination links on that page i.e. so only a certain amounts of products can be shown.

 

The href's of each of these page links are:-

 

Popular.html/Page$pagenum

 

When I have your rewrite rule in place clicking the page 2 link for example goes to:-

 

http://www.mytestsite.com/myshopsite/myproducts.co.uk/Popular.html/Page2

 

where it seems the right items are being shown but there is no css for some reason.

 

However when I click another page link such as page 1 for example from the page 2 page it goes to:-

 

http://www.mytestsite.com/myshopsite/myproducts.co.uk/Popular.html/Popular.html/Page1

 

Which of course does not exist.

 

Is this a problem with my href of the links? The css disappearing is weird too.

 

Again thanks for trying to help.

OK I've changed my css link from:-

 

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

 

to:-

 

<link href="http://www.mytestsite.com/myshopsite/myproducts.co.uk/styles.css" rel="stylesheet" type="text/css"/>

 

and that makes the css work on the pages pages however now no images are appearing. Does this mean I'll have to add in the full site address for every image like I have done with the css link?

 

Rewriting is the biggest pain in the nuts in the history of all things web related  >:(

 

EDIT - It seems adding the full site address i.e. http://www.mytestsite.com/myshopsite/myproducts.co.uk/images/ before every image fized the images problem

 

However I still have the page problem i.e. if I go to page 2 or any other page on the popular page it goes to something like this:-

 

http://www.mytestsite.com/myshopsite/myproducts.co.uk/Popular.html/Page2

 

BUT if I try to go to another page FROM that page such as page 1 it does this:-

 

http://www.mytestsite.com/myshopsite/myproducts.co.uk/Popular.html/Popular.html/Page1

 

I think it's my hrefs or something.

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.