Reputation: 579
So I have "nice" urls:
RewriteRule ^(.*)/$ page.php?data=$1 [L]
The problem is that page.php
is accessible so site.com/page.php?data=xxx
will show duplicate content of site.com/xxx/
I want to prevent that, but if I do any Redirect
or RewriteRule
even before the nice url RewriteRule
it affects/makes the file inaccessible even behind the nice url.
Is there any way?
I can change page.php
to a rare filename, and in case its discovered and published, add html canonical urls
, but I would like to do it right.
Upvotes: 0
Views: 227
Reputation: 18671
Add this before your first RewriteCond
:
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+page\.php\?data=([^\s&]+) [NC]
RewriteRule ^ /%1/? [R=301,L,NE]
Upvotes: 1