homepage Welcome to WebmasterWorld Guest from 54.161.192.130
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod_rewrite help needed
Can't get spidered!
Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 58 posted 1:42 am on Nov 30, 2002 (gmt 0)

Hello everyone. I've been searching and reading and I'm just confused. I would like to rewrite my dynamic urls to look static. Hopefully I can get it done tonight and maybe have a chance of the pages being indexed next month.

Here is a sample of the current structure:
my_site.com/catalog.html/purple_widgets/3

This is how I'd like it to appear:
my_site.com/purple_widgets/3.html

Could someone please help me out with this. I know it's best to learn to catch fish, instead of asking for a fish but if you give me a fish(rewrite code:)) for this problem I'll learn to catch my own in the future.

Thanks

 

DaveAtIFG

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 58 posted 9:54 am on Nov 30, 2002 (gmt 0)

Here are a few pages to get you started:

[httpd.apache.org...]
[httpd.apache.org...]
[etext.lib.virginia.edu...]

One of our regular mod_rewrite wizards will probably be along soon to offer suggestions.

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 58 posted 1:45 pm on Nov 30, 2002 (gmt 0)

This is probably seriously flawed, but I'll take a stab(Throws out lure in attempt to catch a fish).

This is how I want the urls to appear:
/red_widget_catalog.html
and
/red_widget_info/1.html
Then be rewritten to:
/widget_catalog.html/red_widgets
and
/widget_info.html/1

RewriteEngine On
RewriteRule ^(.*)_widget_catalog\.html$ /widget_catalog\.html/$1
RewriteRule ^(.*)_widget_info/([0-9+])\.html$ /widget_info\.html/$1/$2

Disregard the first post. I believe this is the structure I would prefer.

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 58 posted 4:23 pm on Nov 30, 2002 (gmt 0)

>>>(Throws out lure in attempt to catch a fish)

Switches from lure to live bait;)

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 58 posted 4:27 pm on Nov 30, 2002 (gmt 0)

Birdman,

try checking out some of the other rewrite threads in technology. There are tons of them. Maybe you can catch your own fish then. ;)

DaveAtIFG

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 58 posted 5:11 pm on Nov 30, 2002 (gmt 0)

The expression on the left is a regex pattern, the expression on the right is a literal destination as in:
RewriteRule ^(.*)_widget_catalog\.html$ /widget_catalog.html/$1

I think the the expression on the right needs the variable added differently as in:

RewriteRule ^(.*)_widget_catalog\.html$ /$1_widget_catalog.html
not sure though, don't recall ever seeing this type rule...

Setup a test page and try it on your server.

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 58 posted 3:58 pm on Dec 1, 2002 (gmt 0)

Thanks for the help, everyone. One more question:

RewriteRule ^(.*)_widget_catalog\.html$ /$1_widget_catalog.html

Does the first part(bold) grab everything before _widget_catalog, including the http://

The string I really want to get is ht*p://www.mysite.com/red_widget_catalog.html

Thanks again for the help. I'm starting to get it:)

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 58 posted 4:50 pm on Dec 1, 2002 (gmt 0)

Birdman,

As DaveAtIFG pointed out,
The expression on the left is a regex pattern, the expression on the right is a literal destination...

The string on the left starts in your top-level directory file path, not with "http://www.yourdomain.com".

The string on the right can start with "http://www.yourdomain.com", but unless you want to redirect off-site, leave it off.

Thanks for the help, everyone. One more question:
RewriteRule ^(.*)_widget_catalog\.html$ /$1_widget_catalog.html
Does the first part(bold) grab everything before _widget_catalog, including the http://

If your RewriteRule is located in a .htaccess file in your top-level (web-visible) directory, then "^(.*)" grabs everything in the file path up to "_widget_catalog...", starting after "http://www.yourdomain.com/". If the RewriteRule is located in .httpd (above the directory levels accessible from the web) then "^(.*)" grabs the slash as well, as in "/red" in your example.
The parentheses around ".*" mean that it is either a text grouping or that you wish to back-reference the contents using $1, $2, etc. - It looks like you've got that concept.

The string I really want to get is ht*p://www.mysite.com/red_widget_catalog.html

The RewriteRule will be applied to any method (e.g. http, https) and any domain that "lands" in your top level directory or below. If you need to exclude certain methods or domains from being affected by a RewriteRule, you can use RewriteCond to exclude them. The system variables %{REQUEST_METHOD} and %{HTTP_HOST} will pick up the HTTP vs. HTTPS, etc., and the domain name used in the request, respectively.

It looks like you're basically on the right track here. A couple of tweaks to make your rules correspond with what you said you wanted to accomplish (assuming you're doing this in .htaccess):

RewriteEngine On
# rewrite /red_widget_catalog.html -> /widget_catalog.html/red_widgets
RewriteRule ^(.*)_widget_catalog\.html$ /widget_catalog.html/$1_widgets
#
# rewrite /red_widget_info/1.html -> /widget_info.html/1
RewriteRule .*_widget_info/([0-9+])\.html$ /widget_info.html/$1
# (The start anchor and first set of parentheses are not needed in this case)

HTH,
Jim

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 58 posted 5:02 pm on Dec 1, 2002 (gmt 0)

Thank you for that very detailed and helpful explanation, Jim. I'm seeing it clearer than ever now:), albeit I've got a long way to go.

Marty

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 58 posted 10:17 pm on Dec 3, 2002 (gmt 0)

Just wanted to report the outcome of my dilemma. I got all the url "spider friendly" yesterday. Just got home from my real job today and checked for Gbot. It took the whole site:)

Thanks again,
Birdman

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 58 posted 10:31 pm on Dec 3, 2002 (gmt 0)

Congrats Marty :)

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 58 posted 3:43 am on Dec 4, 2002 (gmt 0)

Glad to hear it, Birdman!

Jim

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