desperately need help figuring out rewrite rules

New to mod_rewrite? This is a good place to start.

desperately need help figuring out rewrite rules

Postby cvbooks » Wed Jun 02, 2004 12:03 pm

I need some help determining how to write some rules for mod_rewrite.
I apologize for bothering you with these questions, but I can't catch on to the mod_rewrite syntax well enough to feel confident to do this on my own.

Basically, I need to convert static URLs of the following format:

mydomain.com/item1.html
to the following:
mydomain.com/index.mv?doc=item1

in other words, the name of the html file will always become the value of the variable 'doc'.

Also, whatever variables that follow an html file, for example:
mydomain.com/item1.html?mode=ext
need to be included in the converted URL as such:
mydomain.com/index.mv?doc=item1&mode=ext

The last rule is the simplest:
mydomain.com/index.html
needs to be converted to:
mydomain.com/index.mv

So basically, I think I need only three rules. Correct?

Thank you very much in advance,

-Creative Visions
cvbooks
 

Postby seomike » Wed Jun 02, 2004 9:03 pm

nothing like a miva mod :)

Start your .htaccess file with this

RewriteEngine On
Options +followsymlinks
RewriteBase /

#1 code to rewrite the .html as .mv for the index
RewriteCond %{REQUEST_URI} ^/index\.html$
RewriteRule ^index\.html$ /index.mv [L]

#2 code for "mydomain.com/item1.html"
RewriteCond %{REQUEST_URI} ^/.*\.html$
RewriteRule ^(.*)\.html$ /index.mv?doc=$1 [L]

#3 code for "mydomain.com/item1.html?mode="
RewriteCond %{REQUEST_URI} ^/.*\.html\?.*$
RewriteRule ^(.*)\.html\?mode=(.*)$ /index.mv?doc=$1&mode=$2 [L]

#end mod rewrite


As an SEO I would change the on page code to out put
/item1-ext.html instead of /item1.html?mode=ext
Basically if you're going to make it SE friendly might as well be thorough.
If you opt to do that change #3 to this

#3code for "mydomain.com/item1-mode.html"
RewriteCond %{REQUEST_URI} ^/.*-.*\.html$
RewriteRule ^(.*)-(.*)\.html$ /index.mv?doc=$1&mode=$2 [L]

Also if at all possible instead of linking to domain.com/index.html just link back to the http://www.domain.com/. You should always build the domains PageRank in Google instead of the index pages. That way you can change file names and not have to worry about affecting the sites rankings Same goes for sub folders link to www.domain.com/folder/ not www.domain.com/folder/index.html 8)

That should do it :D
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 33 guests

cron