Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache mod_rewrite:How to;“白名单”;网址?_Apache_.htaccess_Mod Rewrite_Url Rewriting_Uri - Fatal编程技术网

Apache mod_rewrite:How to;“白名单”;网址?

Apache mod_rewrite:How to;“白名单”;网址?,apache,.htaccess,mod-rewrite,url-rewriting,uri,Apache,.htaccess,Mod Rewrite,Url Rewriting,Uri,我正在使用mod_rewrite来获得更好的URL。因此,目前有两种访问页面的方式: 直接访问: 使用mod_重写访问: 只有使用mod_rewrite才能访问网站。换句话说,我想“白名单”某些uri并阻止每个不同的uri 我考虑过要有一个带有“END”标志的RewriteRules列表,所以如果上面的规则都不匹配,最后一个将阻止请求。这是可行的,但它也会阻止我的index.php站点。此外,这并不是最好的方法。可以使用RewriteCond列出某些页面,并使用RewriteRule捕获所有

我正在使用mod_rewrite来获得更好的URL。因此,目前有两种访问页面的方式:

  • 直接访问:
  • 使用mod_重写访问:
只有使用mod_rewrite才能访问网站。换句话说,我想“白名单”某些uri并阻止每个不同的uri


我考虑过要有一个带有“END”标志的RewriteRules列表,所以如果上面的规则都不匹配,最后一个将阻止请求。这是可行的,但它也会阻止我的index.php站点。此外,这并不是最好的方法。

可以使用
RewriteCond
列出某些页面,并使用
RewriteRule
捕获所有响应404错误

# if the request uri is not /mypage.php and /otherpage.php
RewriteCond %{REQUEST_URI} !^/(mypage|otherpage)\.php

# if the request uri is not /startpage
RewriteCond %{REQUEST_URI} !^/startpage

# response 404 error
RewriteRule ^ - [R=404,L]

可以使用
RewriteCond
列出某些页面,并使用
RewriteRule
捕获所有响应404错误

# if the request uri is not /mypage.php and /otherpage.php
RewriteCond %{REQUEST_URI} !^/(mypage|otherpage)\.php

# if the request uri is not /startpage
RewriteCond %{REQUEST_URI} !^/startpage

# response 404 error
RewriteRule ^ - [R=404,L]