right way modrewrite and QUERY_STRING

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

right way modrewrite and QUERY_STRING

Postby ceasar » Sat Aug 08, 2009 10:30 pm

Hai all,

I have a small question about modrewrite
At the moment I have it all working but don't know if this is the right way

I have two url's
index.php?quiclink=something and
actueel.html?some-text&artikelenID=1&print=true

In my htaccess I have the following rules

RewriteRule ^$ home.html
RewriteRule ^([0-9a-zA-Z\]+)-([0-9a-zA-Z\-]+)-([0-9]+)\.html$ index.php?quicklink=$1&artikelenID=$3\&%{QUERY_STRING}
RewriteRule ^([0-9a-zA-Z_\-]+)\.html$ index.php?quicklink=$1\&%{QUERY_STRING}

This works as expected. But on this forum I see that most of the time [QSA,L] is being used at the end of the rule. So what will be the best way ? And what is the difference ?

RewriteRule ^([0-9a-zA-Z\]+)-([0-9a-zA-Z\-]+)-([0-9]+)\.html$ index.php?quicklink=$1&artikelenID=$3 [QSA,L] or

RewriteRule ^([0-9a-zA-Z\]+)-([0-9a-zA-Z\-]+)-([0-9]+)\.html$ index.php?quicklink=$1&artikelenID=$3\&%{QUERY_STRING}

Thanks for the help
ceasar
 
Posts: 5
Joined: Sat Aug 08, 2009 10:18 pm

Dynamic to Static URL's 301 Redirect

Postby ceasar » Sun Aug 09, 2009 4:20 am

And another perhaps stupid question :)

To avoid duplicated content I see a lot of solutions on this board
With php or RewriteCond

But what about doing it in robots.txt

example
old - actueel.html?sometext&artikelenID=id&print=true
new - actueel-sometext-id.html

and then in the robots.txt

Disallow: /*artikelenID=*

Google will still crawl the old url but it won't show up in the google results
Is this bad or a nice solution ?
ceasar
 
Posts: 5
Joined: Sat Aug 08, 2009 10:18 pm

Postby richardk » Wed Aug 12, 2009 11:37 am

This works as expected. But on this forum I see that most of the time [QSA,L] is being used at the end of the rule. So what will be the best way ? And what is the difference ?

They do the roughly same thing. Use the QSA (Query String Append).

You should also use the L (Last) flag so when a rule matches the processing stops
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^$ /home.html [QSA,L]
RewriteRule ^([-a-zA-Z0-9]+)-([-a-zA-Z0-9]+)-([0-9]+)\.html$ /index.php?quicklink=$1&artikelenID=$3 [QSA,L]
RewriteRule ^([0-9a-zA-Z_\-]+)\.html$ /index.php?quicklink=$1 [QSA,L]


But what about doing it in robots.txt

example
old - actueel.html?sometext&artikelenID=id&print=true
new - actueel-sometext-id.html

and then in the robots.txt

Disallow: /*artikelenID=*

Google will still crawl the old url but it won't show up in the google results
Is this bad or a nice solution ?

Does "/*artikelenID=*" work in robots.txt files?
One problem is that the users/robots visiting the old URL will not get sent to the new working URL.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ceasar » Wed Aug 12, 2009 12:00 pm

Hai richard

Thanks for the explanation
Yup the flag in robots.txt works
You can use wildcards like /pdf.php?* or /index.php?page=* ect.

info
http://www.seobook.com/archives/001329.shtml
http://www.seoegghead.com/blog/seo/wild ... -p158.html
ceasar
 
Posts: 5
Joined: Sat Aug 08, 2009 10:18 pm

Postby richardk » Wed Aug 12, 2009 12:04 pm

Thanks for the information.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ceasar » Sat Aug 15, 2009 11:43 pm

Hai richard.

Still one more question :)

On my local server this rules works (apache 1.3.6)
RewriteRule ^([0-9a-zA-Z\-]+)-([0-9a-zA-Z\]+)-([0-9]+)\.html$ index.php?quicklink=$2&artikelenID=$3 [QSA,L]

but on my live server this gives a 500 error (apache 2)

There I have to set it to

RewriteRule ^([-a-zA-Z0-9]+)-([-a-zA-Z0-9]+)-([0-9]+)\.html$ /index.php?quicklink=$2&artikelenID=$3 [QSA,L]

What could be the problem or how can I set it that it works on both servers ?

Thanks
ceasar
 
Posts: 5
Joined: Sat Aug 08, 2009 10:18 pm

Postby ceasar » Sun Aug 16, 2009 12:18 am

Solved :)

fogot an - after Z\
ceasar
 
Posts: 5
Joined: Sat Aug 08, 2009 10:18 pm

Postby richardk » Sun Aug 16, 2009 7:17 am

If you put the dash first you don't need to escape it
Code: Select all
[-a-zA-Z0-9]+
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 18 guests

cron