正则表达式 – 在htaccess RewriteRule中排除特定的子域或没有子
我在我的网络应用程序的不同子域上保留了动态内容和静态内容,但我最近发现如果直接调用动态内容可以在我的静态子域(www.)上查看,或者根本没有子域.
网址结构: http(s)://(subdomain).(domain).(tld)/(static page) OR (direct/random hash) OR (secure/random hash) 所有静态内容都可以通过“WWW”访问,这导致我的SEO友好域名,如 http(s)://www.domain1.com/about http(s)://www.domain1.com/ http(s)://www.domain2.com/about http(s)://www.domain2.com/ 通过网络应用程序查看的动态内容可以从域等访问 http(s)://dynamic1.domain1.com/direct/randomhash http(s)://dynamic2.domain1.com/direct/randomhash http(s)://dynamic1.domain2.com/direct/randomhash http(s)://dynamic2.domain2.com/direct/randomhash 这是我当前的.htaccess文件 重写URI以安全或直接开头的动态链接以及index.php文件的任何文件扩展名的规则. Header set Connection keep-alive <IfModule mod_dir.c> DirectorySlash Off </IfModule> <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^index.php - [L] RewriteRule ^(secure|direct) /index.php [L] RewriteCond %{REQUEST_URI} !^/server-status RewriteCond %{REQUEST_URI} !^/public/cache RewriteRule !.(png|gif|css|jpg|zip|js|html|htm|swf|ico|fon|ttf|otf|svg|woff|woff2|eot)$ /index.php [L] </IfModule> 以上目前正在运行但我的问题是,如果用户只是将用于动态内容的子域更改为WWW,它仍然可以工作,并且将导致可以从我的SEO友好子域访问动态内容. 我希望能够编辑这个规则RewriteRule ^(secure | direct)/index.php [L],以便在有活动的www时将其排除.子域或没有子域,如果域或子域是其他任何东西仍在工作. 也就是说,子域或域仍然是通配符,除非子域是www. 我假设我必须将%{HTTP_HOST}添加到RewriteRule ^(secure | direct)/index.php [L]并使用正则表达式来允许任何子域,域和tld,但我不知道如何排除if http主机以WWW开头.或根本没有子域名. 我的最终目标是无法通过www查看安全和直接路径.或者在使用任何其他子域/域时没有子域.
您可以使用:
RewriteCond %{HTTP_HOST} ^(?:www.)?[^.]+.[^.]+$[NC] RewriteRule ^(secure|direct) /index.php [L] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |