开发者

htaccess rewrite rule 'page numbers' problem

I've added a .htaccess file to my root folder for the purposes of rewriting dynamic URLs into static ones. This seems to have been done successfully but I am having problems with page numbers.

For example, if you were to visit a static page /widgets, the first page of the products is fine....but subsequent pages show u开发者_开发问答p as /products.php?cat=27&pg=2 etc. What I want is for subsequent pages to be in the form of /widgets-pg2 or /widgets?pg=2.

Below is my rewrite rule that I used for the initial category page:-

RewriteRule ^widgets$ products.php?cat=27

If any of you experts can help with this, it would be much appreciated.


Are you expecting the cat to change as well? You'd need to account for that in your URL as well:

e.g. www.site.com/widgets/27/2 could be rewritten as:

RewriteRule ^widgets/([0-9]+)/([0-9]+)$ products.php?cat=$1&pg=$2

If widgets will always be cat 27 then you can change it to:

RewriteRule ^widgets$ products.php?cat=27 [QSA] 

which is query string append


Try

RewriteRule ^widgets-pg(.+)$ products.php?cat=27&pg=$1

After that, go here :)


To allow a query string after your rewritten URL use the [QSA] flag:

RewriteRule ^widgets$ products.php?cat=27 [QSA]

A link would than be:

http://example.org/widgets?pg=167&perpage=100&tralala=Hi!


I tried the following but it resulted in a '404 Not Found' error when I go to /widgets:-

RewriteRule ^widgets-pg(.+)$ products.php?cat=27&pg=$1

And I tried the following:-

RewriteRule ^widgets$ products.php?cat=27 [QSA]

This worked correctly but to go to page two of the widgets page, I need to type in the browser:-

/widgets?pg=2

But the actual 'page 2' link still leads to:-

products.php?cat=27&pg=2

So apart from a rewrite rule....maybe I need a separate redirection rule? Or maybe need to change the page number links. But since these are dynamically generated, I'm not sure how to do this.

The following is the PHP code for the page:- http://freetexthost.com/3ubiydspzm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜