[英]How do I block a part of an url with htaccess?
So basically, I have a link looking like:所以基本上,我有一个链接看起来像:
mydomain.com/file.php?id=m03u7dp255jiobi&type=mp3
How do I block access to this URL only for this ?id=
part如何仅针对此
?id=
部分阻止访问此 URL
So when users visit this link file.php?id=test
it won't work, but if they visit the other link looking like this ?id=validurl
it will work.因此,当用户访问此链接
file.php?id=test
,它将无法工作,但如果他们访问其他类似?id=validurl
,它将工作。
To do this in .htaccess
you can use the mod_rewrite
module and set conditions against the query string.要在
.htaccess
执行此操作,您可以使用mod_rewrite
模块并针对查询字符串设置条件。
ReWriteCond %{QUERY_STRING} id=invalid_string [OR]
ReWriteCond %{QUERY_STRING} id=another_invalid_string
ReWriteRule . /new_destination.php [QSD,L,R=307]
OR
- Literally an OR
operator; OR
- 字面意思是OR
运算符; as in Condition1 || Condition 2
Condition1 || Condition 2
Condition1 || Condition 2
QSD
- Removes the original query string QSD
- 删除原始查询字符串L
- Stops further rewrite rules from being applied L
- 停止应用进一步的重写规则R=307
- Sets a 307 Temporary Redirect
status code R=307
- 设置307 Temporary Redirect
状态代码
R=401
Sets an Unauthorised status code and redirects automatically to a predefined 401
resource ( ErrorDocument
) R=401
设置未授权状态代码并自动重定向到预定义的401
资源 ( ErrorDocument
)
You can custom set the ErrorDocuments
like:您可以自定义设置
ErrorDocuments
如:
ErrorDocument 401 /errors/unauthorised.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.