如果网页网址包含特定字

时间:2015-10-07 06:47:59

标签: .htaccess mod-rewrite ssl https url-redirection

我的网站在整个SSL上运行,但我添加了一个游戏部分,它们使用闪存中的第三方游戏。当我启用SSL时,它停止工作。我想知道如果我只能在网址中包含“/ game /”的特定页面上禁用SSL,这样游戏才能正常工作。

我在.htaccess文件中从insternet尝试了这段代码,但没有工作:

RewriteCond %{HTTPS} off
RewriteRule ^game^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

编辑:

我尝试了建议的答案:

RewriteEngine On
RewriteCond %{HTTPS} On [NC]
RewriteRule ^game http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]

它有效但当我去包含“游戏”这个词的页面时,它将其他页面也变为“http”,其他页面变成使用“http”而不是“https”

然后我尝试了这个:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} On [NC]
RewriteRule ^game http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]

当我转到“游戏”页面网址时,它开始向我显示“页面未正确重定向”的消息。

我只希望“游戏”页面使用“http”。

编辑两个:完整的.htaccess文件

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]

  # Rewrite all directory-looking urls
  RewriteCond %{REQUEST_URI} /$
  RewriteRule (.*) index.php?rewrite=1 [L,QSA]

  # Try to route missing files
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} public\/ [OR]
  RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
  RewriteRule . - [L]

  # If the file doesn't exist, rewrite to index
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]

</IfModule>

# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On

# @todo This may not be effective in some cases
FileETag Size

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>

需要帮助。如果发现任何重复,请告诉我,但我找不到任何人。 谢谢。

1 个答案:

答案 0 :(得分:0)

这应该是你的全部.htaccess:

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On

  # except for /game/ enforce https
  RewriteCond %{HTTPS} off
  RewriteCond %{THE_REQUEST} !/game/ [NC]
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # for /game/ enforce http
  RewriteCond %{HTTPS} on
  RewriteCond %{THE_REQUEST} /game/ [NC]
  RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # Get rid of index.php
  RewriteCond %{REQUEST_URI} /index\.php
  RewriteRule (.*) index.php?rewrite=2 [L,QSA]

  # Try to route missing files
  RewriteCond %{REQUEST_FILENAME} public [OR]
  RewriteCond %{REQUEST_URI} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
  RewriteRule . - [L]

  # If the file doesn't exist, rewrite to index
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]

</IfModule>

确保在测试此更改之前清除浏览器缓存。