Question

I am having following URL:

http://www.efilmsworld.com/film.php?url=blended-film-2014

And I am using the following in .htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\.html$ /film.php?url=$1 [L,QSA]

Which rewrites my url to:

http://www.efilmsworld.com/blended-film-2014.html

Until this point it’s fine. But the problem is i have both working URLs and it duplicate the contents which is not good:

efilmsworld.com/film.php?url=blended-film-2014
efilmsworld.com/blended-film-2014.html

So I need to remove query string url such as:

efilmsworld.com/film.php?url=blended-film-2014
Was it helpful?

Solution

Adding

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /film\.php\?url=(.*)\ HTTP
RewriteRule ^ /%2.html? [R=301,L]

to your htaccess will solve that.

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /film\.php\?url=(.*)\ HTTP
RewriteRule ^ /%2.html? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)\.html$ /film.php?url=$1 [L,QSA]

What will happen is

  1. if efilmsworld.com/film.php?url=blended-film-2014 is entered then the url will get rewritten to efilmsworld.com/blended-film-2014.html and then silently rewritten (i.e. the url in address bar doesn't change) back to efilmsworld.com/film.php?url=blended-film-2014 so the content is still shown.
  2. if efilmsworld.com/blended-film-2014.html is entered, it is silently rewritten to efilmsworld.com/film.php?url=blended-film-2014 (this you were doing already.
  3. the [R=301] flag tells browsers (and search engines) that the url has changed and can now be found at sometitle.html. That page is now only shown once, so no more duplicate content.

EDIT: As per comment request.

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /video\.php\?url=(.*)\ HTTP
RewriteRule ^ /video/%2.html? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^video/([^/]*)\.html$ /video.php?url=$1 [L,QSA]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top