- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在 StackOverflow 上搜索过这个问题的答案,看到很多问题都接近尾声,但对我来说还没有任何效果。
我想要我的 .htaccess
根据调用它的域应用不同的规则。基本上,如果 subdomain.example.com 被点击,重定向到 google.com。如果命中 localhost,则重定向到 yahoo.com。如果 www.example.com(或 example.com)被点击,重定向到 bing.com。
稍后我将添加实际的重写规则(设置环境变量和 htpasswd 保护),但首先我需要让“if then”部分工作。
我的(非工作)代码如下。任何帮助是极大的赞赏。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$
RewriteRule http://google.com/ [L,R=301]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule http://yahoo.com/ [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule http://bing.com/ [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? - [S=1]
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? - [S=7]
RewriteRule ^(.*)$ /subdir/www/index.php/$1 [L]
RewriteRule ^ - [E=MYSQL_DB_HOST:localhost]
RewriteRule ^ - [E=MYSQL_DB_NAME:XXX]
RewriteRule ^ - [E=MYSQL_USERNAME:XXX]
RewriteRule ^ - [E=MYSQL_PASSWORD:XXX]
RewriteRule ^ - [E=BASE_URL:XXX]
RewriteRule ^ - [E=ENVIRONMENT:XXX]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? - [S=1]
RewriteRule ^(.*)$ /index.php/$1 [L]
最佳答案
如果您使用的是 Apache 2.4,您可能会发现这很有用。
我的服务器设置了一个环境变量 HTTPS
如果通过 HTTPS 连接,尽管有不同的方式来获取它。我的目标是强制 HTTP 身份验证,但仅限于安全连接并将非安全连接重定向到安全位置。
<If "%{HTTPS} == 'on'">
AuthName "Files are protected, enter your normal website email and password"
AuthType Basic
AuthUserFile /home/sites/mysite.co.uk/.htpasswd
Require valid-user
</If>
<Else>
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</Else>
关于apache - 如何在 .htaccess 中编写 "if...else"mod_rewrite 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11528634/
我在这里寻求帮助。我正在尝试将 lighttpd mod_rewrite 转换为 apache mod_rewrite 在这里。轻型服务器 url.rewrite-once = ( "/tor
快速一: 我很好奇是否有人知道在某些情况下 $_SERVER['REQUEST_URI']将包含与 $_GET['_uri'] 不同的值,给定以下 .htaccess对于后者: RewriteCond
.htaccess mod_rewrite 是否需要以下打开/关闭标签?我已经让 .htaccess 在没有这些的情况下工作,但只是检查了 htaccess 教程,很多都包含这个标签。 ... 最
我正在尝试对我的电子商务网站进行一些改进,以获得更好的搜索引擎优化。更重要的事情之一是将产品设置为不使用旧的: /detail.php?pid=367 相反,我们设置了 8 个顶级类别,在 8 个顶级
我正在从 Apache 中的 Django FastCgi 设置迁移到 lighttpd 中的设置。 在 Apache 上,我使用 Django 文档中描述的 fcgi 配置。核心部分是将我所有的非静
我是 mod_rewrite 的新手,我正在尝试将我的网址转换为: website.com/profile.php?user=andy 到以下几点: website.com/user/andy 这是我
我正在使用在 tomcat 上运行的 Liferay 6.2 EE,但它的前端是 Apache 服务器。我想重定向用户,以便每当他们点击旧的 liferay URL 时,它就会将他们重定向到新的 li
好的,我正在测试安装在我的个人网络服务器上的 cms(joomla),然后再将其上线。 而且我希望能够阻止使用查询字符串,或者更重要的是阻止用户在查询字符串上输入内容(如 articleid 等更改)
我正在尝试将每个请求发送到 www.example.com/user/至 www.example.com/user.php?id=0使用这个 RewriteRule ^user/$ user.php?
我打算将我的网站转换为新的 CMS,但我想使用 mod_rewrite 将旧链接无缝重定向到新位置。 问题是我的新博客的文章编号与旧的不同,因为我将首先导入一些较旧的博客条目。因此,我的 mod_re
我已与我的主机确认启用了 mod_rewrite。我希望传入的请求被重写以传递到我的根目录中的 mod_rewrite.php 文件。 Mod_rewrite 似乎根本不起作用。这是我的 .htacc
我想重写 URL,以便当有人访问时: url.com/directory1/directory2 他在浏览器地址栏中看到了 URL,但实际上下面的 URL 显示的是文本 url.com/index.p
所以我试图让 mod_rewrite 工作,在 Windows 7 上使用 Apache2.2我将它作为本地服务器运行。所有网站都可以通过 http://localhost/ 访问没用? 我创建了一个
我想使用 Apache 的 mod_rewrite为了能够将路径的每个文件夹作为特定的查询参数,例如考虑以下内容: 基本示例 请求的网址:http://domain.com/shoes/prada/i
我有这个地址http://www.example.com并拥有此页面 http://www.example.com/world . 我可以用 mod_rewrite 做到这一点吗,我的页面变成 htt
我的情况是我需要将所有匹配 http://mywebsite.com/portfolio/[anyname] 的请求定向到 http://mywebsite.com/portfolio.php?用户名
我试图让 Symfony1.4 和 Symfony2 在 Apache(2.2.22)中的同一主机上工作 - 我认为问题在于两者都使用 mod_rewrite 将请求定向到 php Controlle
是否可以使用 mod_rewrite 将内部重定向(因此地址栏中的 url 不会更改)到同一主机上的不同端口? 例如 http://host.com:8080 -> http://host.com:9
我已经为此工作了几个星期。我希望能够使用友好的 URL 将变量传递给 PHP 脚本。例如,如果有人使用此 URL: https://example.com/foo/bar/who 我希望我的 PHP
我需要使用以下 URL 重定向传入请求: http://mywebsite.com/abc/mapserv.exe?map=123 到 http://mywebsite.com/abc/mapserv
我是一名优秀的程序员,十分优秀!