I need help about URL rewriting for image gallery for site.
This is problem, I needed to change hosting so I moved site to another server and there was problem because when it was transfered to that new server site worked without url rewriting, even if .htaccess file was present.
After few days problem is solved and my links look nice again. But search engines crawled my site in time when URL rewriting in .htaccess was not working somehow, so same pages are indexed in both ways, with nice URL and with out URL rewriting.
Like I said links are ok now, but there are a lot of results in data base of search engines which are still opening like that.
Normal fine links produced by CMS image gallery look like this:
http://www.mysite.net/Category/Subcategory/Item-name.html
But, in search engine data base there are still a lot of results witout URL rewriting, with links like this:
http://www.mysite.net/show.php?cat=Category&sub_cat=Subcategory&img=Item-name
Example:
If anyone try to open page it will be opened in both ways, practically you can see the same page opening this:
http://www.mysite.net/Category/Subcategory/Item-name.html
and this
http://www.mysite.net/show.php?cat=Category&sub_cat=Subcategory&img=Item-name
Can you help me with some SEO friendly URL redirect rules
This is part of my .htaccess file related to image gallery.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
######## Begin - URL rewriting for image gallery ########
## For showig category of item
RewriteRule ^(.*)/$ showcat.php?cat=$1 [L]
## For showig subcategory of item
RewriteRule ^(.*)/(.*)/$ showcat.php?cat=$1&subcat=$2 [L]
## For showig item
RewriteRule ^(.*)/(.*)/(.*).html$ show.php?cat=$1&sub_cat=$2&img=$3 [L]
## For latest items
RewriteRule ^latest-page-(.*)/$ latest.php?page=$1 [L]
## For top rated items
RewriteRule ^top/page/(.*)/$ top.php?page=$1 [L]
## For show most rated - most clicked - most downloaded and most searched items
RewriteRule ^most-rated.html$ showmost.php?type=1 [L]
RewriteRule ^most-clicked.html$ showmost.php?type=2 [L]
RewriteRule ^most-downloaded.html$ showmost.php?type=3 [L]
RewriteRule ^most-Searched.html$ showmost.php?type=4 [L]
######## Begin - URL rewriting for image gallery ########
Still, I can not get just this kind of links:
http://www.mysite.net/Category/Subcategory/Item-name.html
I tried your solution, like this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
######## Begin - URL rewriting for image gallery ########
## For showig category of item
RewriteRule ^(.*)/$ showcat.php?cat=$1 [L]
## For showig subcategory of item
RewriteRule ^(.*)/(.*)/$ showcat.php?cat=$1&subcat=$2 [L]
## For showig item
RewriteRule ^(.*)/(.*)/(.*).html$ show.php?cat=$1&sub_cat=$2&img=$3 [L]
## this section should be inserted just after the showing item rule above
#if the query string has cat, sub_cat and Img
RewriteCond %{QUERY_STRING} ^cat=(.+)&sub_cat=(.+)&img=(.+)$ [NC]
#and it is for resource show.php, then 301 redirect to Keyword rich URL
RewriteRule ^show\.php$ http://www.mysite.net/%1/%2/%3.html [NC,L,R=301]
## For latest items
RewriteRule ^latest-page-(.*)/$ latest.php?page=$1 [L]
## For top rated items
RewriteRule ^top/page/(.*)/$ top.php?page=$1 [L]
## For show most rated - most clicked - most downloaded and most searched items
RewriteRule ^most-rated.html$ showmost.php?type=1 [L]
RewriteRule ^most-clicked.html$ showmost.php?type=2 [L]
RewriteRule ^most-downloaded.html$ showmost.php?type=3 [L]
RewriteRule ^most-Searched.html$ showmost.php?type=4 [L]
######## End - URL rewriting for image gallery ########
And now, I can access the same page with this normal URL:
http://www.mysite.net/Category/Subcategory/Item-name.html
And, I guess because of your new URL redirection rule now URL like this:
http://www.mysite.net/show.php?cat=Category&sub_cat=Subcategory&img=Item-name
is redirected to this:
http://www.mysite.net/Item-name.html?cat=Category&sub_cat=Subcategory&img=Item-name
But, you sure know that I wish just this URL:
http://www.mysite.net/Category/Subcategory/Item-name.html
If search engines indexed your site with the old URLs and you have since changed them to keyword rich URLs, then the correct way to let them know to use the new ones is to 301 redirect requests for the old URLs to the new ones.
Edit your current .htaccess file and place the section to redirect the old URLs to the new ones just after the showing item rule, as below.