Need expert advice about Rewriting URL

Discuss practical ways rearrange URLs using mod_rewrite.

Need expert advice about Rewriting URL

Postby askthermal » Tue Nov 04, 2008 12:17 am

i'm currently use a mod_rewrite to redirect my url's, but i don't think it's SEO friendly.

This is my code on htaccess

Options +FollowSymLinks

RewriteEngine On
RewriteBase /
#--------------- rewrite URL ---------------------------------
RewriteRule askpc.html askpc.php [R=301,L]
RewriteRule askpc-([a-z]+)-([0-9]+)/(.*)\.html askpc.php?option=$1&pid=$2 [L]
RewriteRule askpc-([a-z]+)/(.*)\.html askpc.php?option=$1&brand=$2 [L]
RewriteRule askpc-([a-z]+)\.html askpc.php?option=$1 [L]

and it's working just fine, you can see it here http://profiles.waroengdata.com/askpc.html

so....what should i do to make search engine know that all my url's is permanently redirect. thx before.
askthermal
 
Posts: 2
Joined: Tue Nov 04, 2008 12:11 am

Postby richardk » Tue Nov 04, 2008 10:30 am

What URLs do you want redirected?

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^askpc\.html$                      /askpc.php              [R=301,L]
RewriteRule ^askpc-([a-z]+)-([0-9]+)/.+\.html$ /askpc.php?option=$1&pid=$2   [L]
RewriteRule ^askpc-([a-z]+)/(.+)\.html$        /askpc.php?option=$1&brand=$2 [L]
RewriteRule ^askpc-([a-z]+)\.html$             /askpc.php?option=$1          [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby askthermal » Wed Nov 05, 2008 10:12 pm

all my url's, i just want to add R=301, but it redirect to my orignal page ( dynamic page )
askthermal
 
Posts: 2
Joined: Tue Nov 04, 2008 12:11 am

Postby richardk » Thu Nov 06, 2008 8:34 am

So what you really want is a redirect from /askpc.php?option=something to /askpc-something.html?

Mod_rewrite can redirect /askpc.php, /askpc.php?option=a&brand=b and /askpc.php?option=a (try)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?option=([^&]+)(&.*)?$ [NC]
RewriteCond %2&%{QUERY_STRING} ^([^&]+)&(.*&)?brand=([^&]+)(&.*)?$ [NC]
RewriteRule ^askpc\.php$ /askpc-%1/%3.html? [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?option=([^&]+)(&.*)?$ [NC]
RewriteRule ^askpc\.php$ /askpc-%2.html? [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS}%{QUERY_STRING} ^$
RewriteRule ^askpc\.php$ /askpc.html? [R=301,L]

RewriteRule ^askpc\.html$                      /askpc.php                    [L]
RewriteRule ^askpc-([a-z]+)-([0-9]+)/.+\.html$ /askpc.php?option=$1&pid=$2   [L]
RewriteRule ^askpc-([a-z]+)/(.+)\.html$        /askpc.php?option=$1&brand=$2 [L]
RewriteRule ^askpc-([a-z]+)\.html$             /askpc.php?option=$1          [L]

but not /askpc.php?option=a&pid=1 because it can't guess the part of the URL (/askpc-a-1/this-part.html). You would have to redirect it in your PHP.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Majestic-12 [Bot] and 4 guests

cron