简单的mod重写,没有重复的url.有可能的? [英] Simple mod rewrite with no duplicate urls. It is possible?
问题描述
我已经创建了简单的mod重写
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]
一切正常.我的问题是目前两个URL都在工作.如何预防呢?
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)
我只希望SEO URL,同一概念将我的所有文件应用于此目录(此目录中超过150个URL)
I want only SEO URL, same concept applied my all files in this directory (more than 150 URLs inside this directory)
有可能吗?
推荐答案
我认为您将无法访问真正的.php文件,因为客户端应该可以显示它.
I think you'll have trouble to forbid access to the real .php file, since the client should be able to display it.
如果您使用干净的URL,我认为如果不在代码中注册文件并禁止访问目录,搜索引擎将找不到文件名.
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]
(尝试访问design/的任何人都可以访问/website-designing.php:没有重定向,因此您不会在地址栏中看到该名称).
(Any one trying to access design/ got served /website-designing.php : no redirect so you won't see the name in the address bar).
我从未使用过nosubreq [NS]
标志.据说它过滤模块生成的内部子请求.但不确定它是否可以与内部HTTP调用一起使用. (由于重写规则会触发新请求,因此将重新处理所有规则,因此您不能只是拒绝访问所有.php文件)
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)
也许您可以尝试:
RewriteRule ^.*\.php$ - [F,NS]
但是不要期望很多.
我会尝试一些技巧,看看是否有效果.
I'll try some tricks to see if something works.
似乎我们可以用:REDIRECT_URL
或REQUEST_URI
做一些事情,似乎它们在重写方面很保守.像:
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]
当您在地址栏中调用.php文件时,这应该禁止任何访问.
This should forbid any access when you call a .php file in the address bar.
这篇关于简单的mod重写,没有重复的url.有可能的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!