Forum Moderators: phranque

Message Too Old, No Replies

Search Engine Optimization using mod_rewrite

RewriteCond syntax wrong

         

seo2000

3:37 pm on Jan 12, 2006 (gmt 0)



Hi,
I want to apply a rewrite rule to simplify dynamic web pages and to get search engines to see them as simple url's to ensure search engine crawlers see all dynamic pages.

I am using httpd.conf with Apache 1.3 on linux.

The first rewrite rule works correctly so that I can enter /show_job.cgi/j/nnn where nnn is an id number. This displays correctly as show_job.cgi?j=nnn.

RewriteEngine On
RewriteRule ^/show_job.cgi/j/([0-9]+) /show_job.cgi?j=$1 [R]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /show_job\.cgi\?j=$1\ HTTP/
RewriteRule ^show_job\.cgi$ http://www.example.com/j/?1 [R=301,L]

I want the RewriteCond and second RewriteRule to force /show_job.cgi?j=nnn to display as /show_job.cgi/j/nnn.

However, this does not work. Does anyone know what's wrong with my syntax?

jdMorgan

12:51 am on Jan 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



seo2000,

Welcome to WebmasterWorld!

Completely reverse the transform, not just the lines:


RewriteEngine On
RewriteRule ^/show_job.cgi/j/([0-9]+) /show_job.cgi?j=$1 [L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /show_job\.cgi\?j=([0-9]+)\ HTTP/
RewriteRule ^show_job\.cgi$ http://www.example.com/show_job.cgi/j/%1 [R=301,L]

Although if this were my site, I'd use a friendly url of "/show_job/j<number>" and dump the ".cgi" and the slash following 'j'. And if there wasn't anything else to "show" other than "jobs", I'd dump the "/j" as well, and use a completely-static-looking "/show-job<number>"

Note that an external redirect [R] *must* not be used in the first rule. It will both expose your cgi call to visitor and search engines, and create an 'infinite loop' with the second rule.

Jim