Forum Moderators: phranque

Message Too Old, No Replies

Simple query based rewrite?

         

jake66

1:47 am on Jun 28, 2007 (gmt 0)

10+ Year Member



Current URL:

/brand/Some_Stuff.html?page=10

Wanted URL:
/brand/Some_Stuff/page10.html

What am I doing wrong?

RewriteRule ^/?(brand//([^/]*)\/page)/([^/]*)\.html$ index.php?manufacturers_id=$2&%{QUERY_STRING}?page=$2&%{QUERY_STRING} [NC]

I am getting 404s with this code.

jdMorgan

3:05 am on Jun 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Which do you want, the URL form you described in words, or the URL-form implied by the code? They are completely different, and this is rather confusing to potential respondents...

Jim

jake66

3:40 am on Jun 28, 2007 (gmt 0)

10+ Year Member



The code I posted is what I was using when trying to execute the URL I want. The two examples above are script-default.. the other what I want it to be after re-write.

As you can see, my skills of mod_rewrite are non-existent. :)

jdMorgan

4:19 am on Jun 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, to rewrite a request for
/example.com/brand/<something>/page<numbers>.html to /brand/<something>.html?page=<numbers>
carrying over (back-referencing) the <something> and <numbers> from the requested URL to the actual server filepath, you'd write:

RewriteRule ^brand/([^/]+)/page[0-9]+\.html$ /brand/$1.html?page=$2 [L]

This presumes that the code is in /example.com/.htaccess, and that you already have other working rewriterules in that file. If not you'll need to set up and enable the rewriting engine before using the rule above, using either only the second or both of the following directives (you have to test to see if the first directive is required, not needed, or not allowed on your particular server):

Options +FollowSymLinks
RewriteEngine on

Having installed all of that, you'll then need to change all of the links on your pages to use the new URL format. When someone clicks on one of the new-format links, that new URL will be requested from your server, and the rewriterule will then re-format it and pass it to the content-handler, which will serve the page. Or if <something.html> is actually a script, it will invoke that script, passing "page=<number>" to it.

This stuff is complicated at first, and can be very dangerous to your search engine rankings. Please devote the time that your site deserves to studying the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com]. Then proceed and experiment cautiously, until you get comfortable with it. We welcome specific questions here!

Jim

jake66

9:24 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



Thank you jdMorgan, that is the basis of what I am trying to achieve.

However, when I click to /brad/brandpage/page2.html I am being displayed the first page still.

Also, I realize I am walking in dangerous waters in regards to SEO. I was hoping to impliment a 301 after I got the rewrite working smoothly. (A 301 from /brand/Some_Stuff.html?page=10 to /brand/Some_Stuff/page10.html )

jdMorgan

12:09 am on Jul 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I forget a pair of parentheses:

RewriteRule ^brand/([^/]+)/page[b]([0-9]+)[/b]\.html$ /brand/$1.html?page=$2 [L]

Jim

jake66

4:41 pm on Jul 21, 2007 (gmt 0)

10+ Year Member



Thank you very much!

I am wondering if this matters any:

/brand/..etc is rewritten:

RewriteRule ^brand/([^.]+)\.html$ index.php?manufacturers_id=$1&%{QUERY_STRING} [NC,L]

so essentially, am I re-rewriting with:

RewriteRule ^brand/([^/]+)/page([0-9]+)\.html$ /brand/$1.html?page=$2 [L]

Initially, the bald URL(s) are:
index.php?manufacturers_id=99

1st rewrite: /brand/brand99.html
2nd rewrite: /brand/brand99/page2.html

Should the two be condensed or does it not matter having 2 rewrites for the same URL?

jdMorgan

4:56 pm on Jul 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since I'm not aware of all of your rules I can't be sure, but I'd recommend you do it all at one go.

Always place more-specific external redirect rules first, then less-specific, and end up with your "catch-alls". After that, start your most-specific internal rewrites, then less-specific, then catch-alls.

Each rule should be written to take the requested URL and rewrite or redirect it to the final destination, avoiding intermediate steps whenever possible.

This is a ranking-related issue for external redirects, and an efficiency-related issue for internal rewrites. Doing all of your external redirects first avoids having them "expose" your internal rewrites to clients.

Jim

jake66

1:47 am on Jul 22, 2007 (gmt 0)

10+ Year Member



Thanks for the clarification.

As for my other rules, they aren't really related to these pages at all, as they rewrite other URL structures / portions of the site.

I'm having a bit of difficulties merging the two together.
I would like the first bit to remain without a number, but once I get to pages 2 and beyond, to use the pageXX.html

Am I looking at this correctly?

RewriteRule ^brand/([^/]+)/([0-9]+)\.html$ /brand/$1.html?page=$2 [L]

..But with this, I'm no longer pushing the "pageXX", just:
brandpage/20.html

Or do you recommend simply dropping the "page"? By my preferences, I don't really have a preference for keeping it. I just want clean looking URLs that bots can follow easily.

jdMorgan

2:04 am on Jul 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Most specific rule first:

RewriteRule ^brand/([^/]+)/page([0-9]+)\.html$ index.php?manufacturers_id=$1&page=$2 [L]
RewriteRule ^brand/([^.]+)\.html$ index.php?manufacturers_id=$1 [L]

Jim