charmeleon
charmeleon

Reputation: 2755

Rewrite, Redirect, and avoid duplicate content

I'm trying to redirect a single page using .htaccess. The actual file is /abc.php, I want it to appear as /abc. So these are my pseudo-rules:

For SEO purposes, only one of /abc and /abc.php should be available.

My naive approach is this:

Redirect 301 /abc.php /abc
RewriteRule ^abcs$ /abc.php [NC,L]

This is causing infinite, looping redirects. How do I do this correctly?

Upvotes: 1

Views: 433

Answers (1)

anubhava
anubhava

Reputation: 785481

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+(abc)\.php[\s?] [NC]
RewriteRule ^ %1? [R=302,L]

# internal forward from pretty URL to actual one
RewriteRule ^(abc)/?$ $1.php [L,NC]

Upvotes: 3

Related Questions