小编Ana*_*log的帖子

在htaccess RewriteRule中排除特定子域或没有子域

我在我的网络应用程序的不同子域上保留了动态内容和静态内容,但我最近发现如果直接调用动态内容可以在我的静态子域(www.)上查看,或者根本没有子域.


网址结构:

http(s)://(subdomain).(domain).(tld)/(static page) OR (direct/random hash) OR (secure/random hash)
Run Code Online (Sandbox Code Playgroud)

所有静态内容都可以通过"WWW"访问,这导致我的SEO友好域名,如

http(s)://www.domain1.com/about
http(s)://www.domain1.com/
http(s)://www.domain2.com/about
http(s)://www.domain2.com/
Run Code Online (Sandbox Code Playgroud)

通过网络应用程序查看的动态内容可以从域等访问

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
Run Code Online (Sandbox Code Playgroud)

这是我当前的.htaccess文件

重写URI开头的动态链接的规则,secure或者directindex.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>
Run Code Online (Sandbox Code Playgroud)

以上目前正在运行但我的问题是,如果用户只是将用于动态内容的子域更改为WWW,它仍然可以工作,并且将导致可以从我的SEO友好子域访问动态内容.

我希望能够编辑此规则,RewriteRule ^(secure|direct) /index.php [L]以便在存在活动www.子域或没有子域的情况下将其排除在外,如果域或子域是其他任何内容,则仍在工作.

也就是说子域或域仍然是通配符,除非子域是 www.


我假设我要补充%{HTTP_HOST}RewriteRule ^(secure|direct) /index.php [L],并使用正则表达式允许任何子域,域,和TLD但林不知道如何如果HTTP主机与WWW开始排除.或根本没有子域名.

我的最终目标是,在仍然使用任何其他子域/域时,无法通过一个子域或无子域查看secure和 …

regex .htaccess mod-rewrite

5
推荐指数
1
解决办法
614
查看次数

用于删除iframe的正则表达式

我正在尝试str_replace用我自己的内容替换所有iframe.我相信我可以使用正则表达式但不完全确定如何删除iframe标记中的所有内容.

由于我不确定如何实现这一点,以下是我一直在使用的.但它只是替换"iframe",所以当一个页面被加载到iframe加载的任何地方时,现在只显示如果iframe要正确解析将加载的URL.

$toremove = str_replace("iframe", "", $toremove);
Run Code Online (Sandbox Code Playgroud)

以下是使用上述代码时加载的内容而不是iframe的示例输出.你可以看到它是整个iframe,只是没有单词"iframe"打破iframe(这比显示它更好)

< src="http://cdn2.adexprt.com/exo_na/center.html" width="728" height="90" frameborder="0" scrolling="no"> 
Run Code Online (Sandbox Code Playgroud)

但现在我想完全删除iframe及其所有内容,这样我就可以将自己的内容放在其中,而不会显示旧的代码.但我不知道如何str_replace使用正则表达式编辑我的作品,而不仅仅是作品"iframe"

php regex iframe str-replace

3
推荐指数
1
解决办法
7618
查看次数

标签 统计

regex ×2

.htaccess ×1

iframe ×1

mod-rewrite ×1

php ×1

str-replace ×1