.htaccess > 4 urls with same page (will google index all?)

I have now 4 url's with from the same file:

All of these links works..

My htaccess:

RewriteEngine On
RewriteRule ^picture/([^/]*)$ /picture.php?name=$1 [L]

In top of my php file (to replace space by -)

$name  = str_replace('-', ' ', $_GET['name']);
$name  = mysql_escape_string($name);
$pic = mysql_query("SELECT * FROM pics WHERE name = '$name'") or die(mysql_error());

But I want to use only: http://domain.com/picture/kim-kardashian, how can I redirect all the other urls to this one using htaccess or php?

And will google index all of these urls or just http://domain.com/picture/kim-kardashian ?

Answers


Add these rules before the one that you have:

RewriteCond %{THE_REQUEST} ^(GET|POST)\ (.*)%20(.*)\ HTTP
RewriteRule . %2-%3 [R=301,NE]

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /picture.php\?
RewriteCond %{QUERY_STRING} ^name=([^&]+)&?(.*)
RewriteRule . /picture/%1?%2 [R=301]

The conditions match against %{THE_REQUEST} so that we aren't matching against a rewritten URI (like one that your rule rewrites to) and that we are matching against the URI that was actually requested. The first redirects URI's with spaces to replace with a dash (one at a time), and the second looks for requests for profile.php and redirects to the SEO friendly version of the URI. After the client gets 301 redirected, your rule will then internally rewrite back to picture.php.

Any links that Google has for the first 3 URIs will eventually get mapped to the 4th because of the 301 redirects.


Need Your Help

Rails integration test against page modification hack?

ruby-on-rails-3 capybara rspec-rails

I'm using Capybara 1.1.2, Rails 3.1.3, rspec-rails 2.9.0, and Ruby 1.9.3p0.

Help with ActiveX Install? Merge Modules - Windows Vista and Windows 7

dll windows-7 install merge-module

I'm building an ActiveX control installer in VS2008 which uses both the CRT and MFC merge modules to install. When my control tries to register on Windows 7 it fails.