.htaccess-Force https,Force to subfolder,Force www,don';破口
我一直很难编辑.htaccess文件来同时完成这三件事。我已经能够分别得到每个部分,但我只是不明白逻辑流程是如何让它们全部工作的 这是我使用bluehost support的演示所能做的最好的一次 我感谢任何帮助解决这个问题.htaccess-Force https,Force to subfolder,Force www,don';破口,.htaccess,mod-rewrite,https,.htaccess,Mod Rewrite,Https,我一直很难编辑.htaccess文件来同时完成这三件事。我已经能够分别得到每个部分,但我只是不明白逻辑流程是如何让它们全部工作的 这是我使用bluehost support的演示所能做的最好的一次 我感谢任何帮助解决这个问题 # Use PHP5 Single php.ini as default AddHandler application/x-httpd-php5s .php # Bluehost.com # .htaccess main domain to subdirectory re
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
# Bluehost.com
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?sampleurl.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/folder/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /folder/$1
# Change yourdomain.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your folder, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?sampleurl.com$
RewriteRule ^(/)?$ folder/index.php
RewriteCond %{HTTP_HOST} ^sampleurl\.com$ [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://www.sampleurl.com/$1 [L]
# For security reasons, Option all cannot be overridden.
# Options All -Indexes
# Options ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch -Indexes
更新:
在使用了很长时间之后,我遇到了一些问题
IndexIgnore *
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule (.*) https://www.example.com/site/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/site/
RewriteRule (.*) https://www.example.com/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule (.*) https://www.example.com/site/$1 [L,R]
新问题
我认为我的一个子域出现的重新定位问题是由于wordpress试图强制一个没有www的域,然后我编写了一个.htaccess文件强制www。这导致了无限循环,而不是我的.htaccess文件。这个线程是关于这个。如果我能解决SimpleDescripts问题,我就是gmoney;) 我想这样的办法会管用的
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) https://www.example.com/folder/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/folder/
RewriteRule (.*) https://www.example.com/$1 [L,R]
但我承认我没有测试过。如果文件存在,可以添加所有的“不重定向”,等等,如果需要的话
如果你还没看到,这是最新的
编辑:
回应最新问题:
我注意到的第一件事是,似乎您对设置有足够的控制权,可以将重写放在Apache配置文件(在VirtualHost部分)而不是htaccess文件中,这将立即解决您与其他站点的问题
第一个问题,听起来您需要添加RewriteCond来排除Bluehost软件使用的URL。或者在不同的VirtualHost下访问Bluehost软件(一旦您将重写内容放入VirtualHost块中)
如果您无法编辑Apache配置,那么对其他站点来说,最简单的修复方法就是不要将它们作为主站点的子目录(在文件系统上)。无论如何,这很奇怪。如果需要,也可以将主站点移动到/www
的子目录
就我个人而言,我把所有网站都放在我的服务器上的
/srv/www/com.site name.www
中(也就是说,颠倒顺序,首先是顶级域,按字母顺序排序时,它会将相关的内容分组在一起。例如,当你有www.example.com和static.example.com时)这似乎可以满足我的所有需要。可能是一个较短的方式来完成这一点,但它的工作!
IndexIgnore*
重新启动发动机
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) https://www.example.com/folder/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/folder/
RewriteRule (.*) https://www.example.com/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) https://www.example.com/folder/$1 [L,R]
除了我尝试的情况外,一切似乎都正常。预期的结果是。这尤其令人遗憾,因为它在没有强制进入目录时会显示文件夹中的所有内容(任何修复此问题的帮助都将不胜感激)。其他一切似乎都起作用了!干杯:)我复制了你的代码,并添加了一个案例,其中使用了443端口,但没有包含文件夹,或者删除了www,似乎可以完成这项工作。谢谢!我不确定您是否收到我的更新通知。如果没有,请看我的问题更新。我感谢你能提供的任何支持。谢谢。@Zane:不,问题更新时不要收到通知。将更新答案。感谢您的反馈。Bluehost使用cpanel。我能看到的唯一apachee配置是Apache处理程序的选项。