Apache mod_rewrite:How to;“白名单”;网址?
我正在使用mod_rewrite来获得更好的URL。因此,目前有两种访问页面的方式: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_重写访问:
我考虑过要有一个带有“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]