Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Script Changes

         

jonescd

6:16 am on Mar 1, 2007 (gmt 0)

10+ Year Member



RewriteEngine on
Options +FollowSymlinks
RewriteBase /

# Rewrite static URLs to dynamic
RewriteRule (.*)\.htm$ /proddetail.php?prod=$1
#
# Redirect only client-requested dynamic URLs to static
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /proddetail\.php\?prod=([^&]+)\ HTTP/
RewriteRule ^proddetail\.php$ [yourstore.com...] [R=301,L]

I am using GoDaddy Linux with Frontpage extensions
The above rewrite is my htaccess code for getting my proddetail pages to redirect from dynamic to .htm urls.

It works fine. However, I also have pages like this one: [mystore.com...]

If I were to perform a rewrite to .htm for that url would I just simply substitute products for proddetail in the htaccess code mentioned above or is there alot more to it than that to change within my includes files that must take place (I know that the mod that I purchased had three files modified in the inc files for the proddetail rewrite mentioned above)?

Thanks,
Chris

jdMorgan

2:13 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Taking the 30,000-foot view, I suspect you may have trouble doing this; By removing the "prod" identifier from the dynamic URL and creating product page URLs that no longer contain any "marker" that says they are products (as opposed to categories), you've made it more difficult to also rewrite/redirect categories. This is because you now risk a "collision" between a product number and a category number.

The work-around is to retain the "cat" identifier in the static URLs for categories, and yes, I suspect that will require some work on the script configuration, or perhaps even on the script code itself.

Ideally, the URL structure of a site with multiple "classes" of pages, such as products, categories, forums, etc. should be designed to retain the class identifiers when changed from dynamic URLs to static URLs. Just as an example, something like:

example.com/show.php?product=100239 --> example.com/prod/100239
example.com/show.php?category=43702 --> example.com/cat/43702

In this way, static URL requests can be rewritten to dynamic pages, and direct dynamic URL requests can be redirected back to static URLs at will, and the potential for collisions between identical numbers belonging to different classes can be avoided.

This answer is general because I know nothing of your site or its URL and file layout, and because I know nothing of the script that you are using. Hopefully, it's still clear enough to make sense, and provide you with an abstract way to define your goals and requirements to avoid problems.

Jim

jonescd

3:46 pm on Mar 1, 2007 (gmt 0)

10+ Year Member



What would be an example of an htaccess script modification to include products.php rather than proddetail.php?Would it be the following? If not what would you add (ps I hired two different developers to do all of this and they dragged their feet. The last one decided to refund my money)?

RewriteEngine on
Options +FollowSymlinks
RewriteBase /

# Rewrite static URLs to dynamic
RewriteRule (.*)\.htm$ /products.cat?prod=$1
#
# Redirect only client-requested dynamic URLs to static
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /products\.php\?cat=([^&]+)\ HTTP/
RewriteRule ^products\.php$ [yourstore.com...] [R=301,L]

jdMorgan

4:48 pm on Mar 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The point is that with this rule
RewriteRule (.*)\.htm$ /products.cat?prod=$1
there is nothing in the pattern to distinguish between products and categories... *Any* .html file will be rewritten to products.cat?prod=<something>. If that's OK with you, then go ahead and test that rule.

It is helpful to look at URLs as "data" provided to mod_rewrite, upon which mod_rewrite will make decisions. By removing any hint of the "type" of page (e.g. product, category, etc.) from the requested URL (usually originating as a link on one of your pages), you take away information that mod_rewrite *may* need to properly direct requested static URLs to dynamic script calls.

Hopefully, that's clearer -- As I said, I can't be more specific because I don't know anything about your URL-layout, file layout, or scripts.

Jim

jonescd

2:33 am on Mar 2, 2007 (gmt 0)

10+ Year Member



Can you recommend a solid programmer for this work?

Thanks,
Chris

jdMorgan

2:38 pm on Mar 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe that with your current URL (on-page link) design, there is no solution. The script that generates the links that appear on your pages will need to be modified to provide the product/category "selector" in the link, so that mod_rewrite will be able to tell them apart. As stated, mod_rewrite needs this "data" to do its job.

Please note that in order to keep this forum spam-free, we allow neither "programmer-for-hire" nor "help wanted" solicitations on WebmasterWorld.

Jim