有多少个htaccess文件?

时间:2017-04-20 15:51:24

标签: .htaccess

我将如何组织htaccess文件? 每个文件夹中都应该有一个文件或文件吗? 我有somedomain / public / .htaccess,它将url字符串放到$_REQUEST['url']变量中。这是下面代码的第二部分,它可以工作。

稍后,我创建了somedomain / .htaccess,其中包含重定向到https://www的代码。
两个单独的文件不起作用,因此我将somedomain / public / .htaccess粘贴到somedomain / .htaccess。但没有任何作用。如何实现这两个功能。我的意思是重定向到https://www并且url获取变量。下面的错误在哪里?

我应该创建somedomain / .htaccess,somedomain / public / .htaccess,somedomain / somefolder / .htaccess,....

或者我只有一个somedomain / .htaccess处理所有重定向? 如果我只有一个somedomain / .htaccess,如下所示,我将如何重定向 somedomainsomedomain/public/index.php somedomain/{url not matching somedomain/public/index.php/parameters}error

文件夹结构

somedomain.com/
      .htaccess
      /public
            #.htaccess #the second part of code, which i copied to somedomain.com/.htaccess
            index.php
somedomain.com /

中的

.htaccess

#first part of htaccess
# Rewrite to HTTPS:
# If www. is already there it will be included, if not
# it will be catched by the subsequent rule.
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
#[L,R=301]

# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} 
#[L,R=301]

RewriteEngine On
# the default webpage loaded by the server:
DirectoryIndex /public/index.php/security/login
IndexIgnore * 

#Second part of htaccess
#rules to fetch controller name and method name starting from /public/index.php/
RewriteBase /public/
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{ENV:REQUEST_FILENAME} !-d
RewriteCond %{ENV:REQUEST_FILENAME} !-f
RewriteCond %{ENV:REQUEST_FILENAME} !-l

RewriteRule ^index.php?(.+)$ index.php?url=$1 [QSA,L] 

我收到错误:服务器遇到内部错误或配置错误,无法完成您的请求。 ... 此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误。

之前我在somedomain.com/public中只有.htaccess的第二部分。

服务器错误日志:

[Thu Apr 20 08:37:36 2017] [error] [client 213.133.81.6] File does not exist: /home/gintare/public_html/typejoy.biz/500.shtml
[Thu Apr 20 08:45:43 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
[Thu Apr 20 08:45:43 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
[Thu Apr 20 08:46:04 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
[Thu Apr 20 08:46:04 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
[Thu Apr 20 08:46:08 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
[Thu Apr 20 08:46:08 2017] [alert] [client 213.133.81.6] /home/gintare/public_html/typejoy.biz/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not included in the server configuration
[Thu Apr 20 10:05:04 2017] [warn] RSA server certificate CommonName (CN) `typejoy.biz' does NOT match server name!?
[Thu Apr 20 10:50:27 2017] [error] [client 115.118.128.202] File does not exist: /home/gintare/public_html/typejoy.biz/favicon.ico
[Thu Apr 20 10:50:27 2017] [error] [client 115.118.128.202] File does not exist: /home/gintare/public_html/typejoy.biz/404.shtml
[Thu Apr 20 10:51:41 2017] [error] [client 115.118.128.202] File does not exist: /home/gintare/public_html/typejoy.biz/favicon.ico
[Thu Apr 20 10:51:41 2017] [error] [client 115.118.128.202] File does not exist: /home/gintare/public_html/typejoy.biz/404.shtml

0 个答案:

没有答案