【问题标题】:how to call index.php as the default, but only for a specific domain?如何调用 index.php 作为默认值,但仅适用于特定域?
【发布时间】:2013-10-15 05:25:38
【问题描述】:

我有几个网站托管在同一台服务器上, 但我猜只有一个 htaccess 文件可以控制所有这些文件。 那么我怎样才能让 index.php 成为这些网站之一的默认值,而不是 index.html 呢?

谢谢!

# -FrontPage-


IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*


<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName site1.com
AuthUserFile /home/myuser/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/myuser/public_html/_vti_pvt/service.grp
AddHandler server-parsed .shtml
AddHandler server-parsed .html

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site1\.com
RewriteRule ^(.*)$ http://www.site1.com/$1 [R=permanent,L]
RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC]
RewriteRule ^(index\.html)?$ /index.php [L,NC]`

【问题讨论】:

  • 你有没有做任何努力或者你希望我们做所有的工作?

标签: .htaccess


【解决方案1】:

对于任何特定站点www.site.com,在您的 .htaccess 中都有此规则:

RewriteCond %{HTTP_HOST} ^(www\.)?site\.com$ [NC]
RewriteRule ^(index\.html)?$ /index.php [L,NC]

建议.htaccess

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site1\.com
RewriteRule ^(.*)$ http://www.site1.com/$1 [R=permanent,L]

RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC]
RewriteRule ^(index\.html)?$ /index.php [L,NC]

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName site1.com
AuthUserFile /home/myuser/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/myuser/public_html/_vti_pvt/service.grp
AddHandler server-parsed .shtml
AddHandler server-parsed .html

【讨论】:

  • 它似乎不起作用,可能是因为我已经设置了之前的规则?另外,如果我希望它同时适用于 www.site.com 和 site.com 怎么办?谢谢RewriteCond %{HTTP_HOST} ^site1\.com RewriteRule ^(.*)$ http://www.site1.com/$1 [R=permanent,L] RewriteCond %{HTTP_HOST} ^(www\.)?site2\.com$ [NC] RewriteRule ^(index\.html)?$ /index.php [L,NC]
  • This rule already works for both www.site.com and site.com。您可以在问题中发布完整的 .htaccess 吗?
  • 好的,如何在代码中插入换行符?双倍空间似乎没有做任何事情:/
  • 不要将代码放入 cmets。编辑您的问题并发布代码。
  • 这条规则我测试了很多次,总是发现index.php是服务器。 Q1。这是唯一的 .htaccess 还是你有另一个? Q2。这是这个.htaccess 中唯一的代码吗?如果您有其他代码(此处未显示),请发布有问题的代码? Q3。上面 .htaccess 的位置是什么?
猜你喜欢
  • 1970-01-01
  • 2013-07-13
  • 2019-07-05
  • 2013-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多