Jump to content
Larry Ullman's Book Forums

Mod_Rewrite And Redirects For Existing Indexed Links


Recommended Posts

I am modularizing a existing site as discussed in Chapter 2.  All is working fine but I cannot seem to find the correct rewrite script for my .htaccess relative to rewriting (or forwarding existing) links that have been indexed in search engines. An example:

 

http://www.example/productdetail.php?id=100 (as indexed by Google) should display as

 

http://www.example/product-detail/100/

 

but instead is displaying in address bar as

 

http://www.example/product-detail/?id=100 (and obviously no page is found)

 

My current .htaccess is:

 

RewriteEngine On

RewriteRule ^([^/]*)/$ /index.php?p=$1[L]

RewriteRule (product-detail)/([^/]*)/$ /index.php?p=$1$id=$2

 

I also have a URL redirect for this page:

Redirect 301 /productdetail.php http:www.example.com/product-detail/

 

Any assistance would be appreciated.

 

Link to comment
Share on other sites

RewriteRule (product-detail)/([^/]*)/$ /index.php?p=$1&id=$2 [L]
RewriteCond %{QUERY_STRING} id=([0-9]+)

I believe I've solved this issue by including the above lines in the .htaccess file.  It now redirects the indexed product id pages to the new, modularized pages.

Link to comment
Share on other sites

 Share

×
×
  • Create New...