Welcome to WebmasterWorld Guest from 54.145.173.36

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

rewrite with pagination

page prepending problems

   
7:34 pm on Apr 23, 2012 (gmt 0)

5+ Year Member



Hi guys,
I have a rewrite which is:

RewriteRule /cid/(.*)/page/(.*)\.php chapter.php?cid=$1&page=$2


now this works fine but when the page bit is taken out then i get a 404.

so

cid/147/page/2


is fine but

cid/147


which is the first page isn't. I can append page/1 to it and that would work but is there something that could make it work without it?
Or is there a better way?
Any help much appreciated.
7:40 pm on Apr 23, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Your pattern requires /page/ to be present. That's why it fails for request without page number.

If you really do require the page number to not be present for page 1, then you will need a second RewriteRule for that.

However, if you do do that, I am willing to bet that requesting page 1 either with or without the page number will both return the same content and that's a duplicate content issue.

Additionally, URLs like /cid/345/page and /cid/ have no meaning - but Google and others will request them for discovery. Using folder levels in your URLs is entirely inappropriate.

Your URLs should look like example.com/c147-p1 (or example.com/c147 ) example.com/c147-p2 example.com/c148-p1 etc.

You do not need .php to be present in your URLs. In fact things become much easier all round if you use extensionless URLs for pages.

URLs for folders always end with a trailing slash.

URLs for files (css, js, images, docs) should usually have an extension.

Do not use (.*) in the first capture. See previous three thousand threads with this warning. If the cid is always numeric, use [0-9]+ instead. Likewise for the page number. This makes requests for cid "4G47" and page "4ev5" directly fail at the Apache level without bogging down your PHP script.

From your PHP script, you must still return a 404 header for all non-valid cid and/or page number combinations.

Each cid should have a unique title and meta description defined, but make sure you also include the page number in the title and meta description so that they are both still unique per page.
10:18 pm on Apr 23, 2012 (gmt 0)

5+ Year Member



thanks for the pm, and the enlightenment, how do i get an extra bit for each page after the query strings i.e

chapter-3-page-1-drama

chapter-4-page-1-comedy
2:29 am on Apr 24, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Do you mean, how do you add the query string in a Rewrite, or how do you take it away in a Redirect? :)

I can't say it's been posted 3000 times, because I haven't been around that long,* but if you putter around this forum you will find some boilerplate on Query Strings and Parameters. Won't repost it here, because it's pretty long and it's only been a few days since last time.


* (joined date about 10 yrs ago x (say it about once a day - allow for holidays)) = yup. He probably really has said it 3000 times ;)
4:03 am on Apr 24, 2012 (gmt 0)

5+ Year Member



I meant to append extra string thats not part of the query ie chapter-1-page-2-drama

The drama bit would be the extra string, is it possible?
6:36 am on Apr 24, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Yes. Add another rule for this. Copy the existing rule and add to the pattern to allow for another hyphen followed by characters.

Add the [L] flag to every rule. Only the rule where the pattern exactly matches will run.

Don't use (.*) in the pattern. It is greedy, ambiguous and promiscuous. Use a more exact match.


@lucy Oh no. Only every other day - but Jim was posting the same stuff in the intermediate days.
4:52 pm on Apr 24, 2012 (gmt 0)

5+ Year Member



thanks for the reply.