homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

rewrite with pagination
page prepending problems

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

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.



is fine but


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)

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)

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




 2:29 am on Apr 24, 2012 (gmt 0)

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)

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)

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)

thanks for the reply.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved