Simple mod rewrite with no duplicate urls. It is possible?
I have created simple mod rewrite
# REMOVE WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]
# URL REWRITE
RewriteEngine on
RewriteRule ^design/?$ website-开发者_运维问答designing.php [L]
Everything working fine. My question is at present both URLs are working. How to prevent this?
mydomain.com/website-designing.php (my original URL)
mydomain.com/design/ (my SEO URL)
I want only SEO URL, same concept applied my all files in this directory (more than 150 URLs inside this directory)
It is possible?
For each RewriteRule ^design/?$ website-designing.php [L]
you could forbid access to corresponding resource.
RewriteRule website-designing.php - [F]
or maybe
RewriteRule .*\.php - [F]
I think you'll have trouble to forbid access to the real .php file, since the client should be able to display it.
If you use clean URLs, I think the search engine can't find the file names if you do not register them in your code and forbid access to directories.
By the way your search engine friendly rewrite should look like :
RewriteRule ^design/$ /website-designing.php [L]
(Any one trying to access design/ got served /website-designing.php : no redirect so you won't see the name in the address bar).
I never used the nosubreq [NS]
flag. It is said it filter internal subrequest generated by modules. But not sure it works with the internal HTTP calls. (Since you rewrite rule trigger a new request, all rules will be reprocessed so you can't just denied access to all .php files)
Maybe you can try :
RewriteRule ^.*\.php$ - [F,NS]
But do not expect many of this.
I'll try some tricks to see if something works.
Edit:
Seems that we can do something with : REDIRECT_URL
or REQUEST_URI
seems it seems they are conserved with rewritting. Like :
RewriteCond %{REDIRECT_URL} \.php
RewriteRule ^.*$ - [F]
RewriteRule ^design/$ /website-designing.php [L]
This should forbid any access when you call a .php file in the address bar.
精彩评论