我是本地ubungu用apache服务器,装drupal7后使用没有问题,装的drupal8后除了首页正常,其他页面都是404,网上看了百度和谷歌,说是什么rewrite的问题,但我看了下自己的设置,貌似没发现问题,而且我装drupal7是能正常使用的。
后来在一个老外试用drupal8-bate版时的贴子,说是.htaccess的问题,我把我装的.htaccess文件的内容全删除。然后把他发上来的.htaccess的内容复制到我的文件里,drupal8其他页面访问变回正常。但老外那个版本是bate版的drupal,写的和现在的有点区别。我尝试只复制我原版.htaccess没有的内容到文件里,无效。
补充一下,我把drupal7的.htaccess替换掉drupall8的.htaccess。drupal8的非首页也能正常访问,我的drupal8是官网下的8.05
所以我想问下,drupal8是不是要自己配的.htaccess,我对运维不懂,要怎么写。我贴一下我原版的和我复制的.htaccess吧,我去掉了注释。
:::我原版的无效的.htaccess:::
<FilesMatch "\.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\..*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
</IfModule>
</FilesMatch>
Options -Indexes
DirectoryIndex index.php index.html index.htm
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
<IfModule mod_php5.c>
php_value assert.active 0
php_flag session.auto_start off
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_flag mbstring.encoding_translation off
php_value always_populate_raw_post_data -1
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A1209600
<FilesMatch \.php$>
</FilesMatch>
</IfModule>
<IfModule !mod_rewrite.c>
FallbackResource /index.php
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^ - [E=protossl]
RewriteCond %{HTTPS} on
RewriteRule ^ - [E=protossl:s]
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule "(^|/)\." - [F]
RewriteBase /drupal
RewriteCond %{REQUEST_URI} ^(.*)?/(install.php) [OR]
RewriteCond %{REQUEST_URI} ^(.*)?/(rebuild.php)
RewriteCond %{REQUEST_URI} !core
RewriteRule ^ %1/core/%2 [L,QSA,R=301]
RewriteRule ^core/install.php core/install.php?rewrite=ok [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_URI} !/core/[^/]*\.php$
RewriteCond %{REQUEST_URI} !/core/modules/system/tests/https?.php
RewriteCond %{REQUEST_URI} !/core/modules/statistics/statistics.php$
RewriteRule "^(.+/.*|autoload)\.php($|/)" - [F]
<IfModule mod_headers.c>
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz|\.css\.gz)$">
Header set Content-Encoding gzip
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
</IfModule>
<IfModule mod_headers.c>
Header always set X-Content-Type-Options nosniff
</IfModule>
-------------------------------------------------------------
:::我复制后有效的.htaccess:::
<FilesMatch ".(engine|inc|info|install|module|profile|test|po|sh|.sql|theme|tpl(.php)?|xtmpl|svn-base)$|^(code-style.pl|Entries.|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
Order allow,deny
</FilesMatch>
Options -Indexes
Options +FollowSymLinks
ErrorDocument 404 /index.php
<Files favicon.ico>
ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>
DirectoryIndex index.php
<IfModule mod_php4.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
</IfModule>
<IfModule sapi_apache2.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
</IfModule>
<IfModule mod_php5.c>
php_value magic_quotes_gpc 0
php_value register_globals 0
php_value session.auto_start 0
php_value mbstring.http_input pass
php_value mbstring.http_output pass
php_value mbstring.encoding_translation 0
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A1209600
ExpiresByType text/html A1
</IfModule>
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
4 个回答
分头诗人Lv 17
不行啊,加了你这段,连首页都不能访问了
我本地网站域名是 localhost/d8test
apache的网站文件夹为 /var/www/html
我还试过把 /var/www 换成了 /var/www/html 或者 /var/www/html/d8test 也不行,连首页都不能访问。
kkLv 9
试下这个看看
cheansLv 10
把<IfModule mod_rewrite.c></IfModule>中的一堆内容换成你的,可行,内页也可以访问
以上是原.htaccess文件就有的,但我仅仅加了
这两条的话,网站连首页也不能访问。
这是什么原理,原.htaccess的
<IfModule mod_rewrite.c></IfModule>有一大堆,删了不知道有没影响kkLv 9