第一次尝试组织一个有两个子域的项目,卡了好几天:
1 - 我的项目组织如下并且在本地运行良好:
project/
|—— admin/
| index.php
| .htacess
| …
|—— shared/
| |—— config/
| | config.php
| | …
| css/
| images/
| functions/
| …
|—— user/
| index.php
| .htacess
| …
2 - 项目托管在共享服务器上(不确定这是否有用)。
3 - 我目前有 2 个子域:“admin.website.fr”和“user.wbesite.fr”,它们分别以我的“admin”和“user”文件夹为根。
4 - 如您所想,我的“config”和“shared”文件夹都包含“admin”和“user”共有的文件。
5 - 这是我的“.htacess”文件的内容:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 7200 seconds"
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/svg+xml "access plus 1 week"
AddType image/x-icon .ico
ExpiresByType image/ico "access plus 1 week"
ExpiresByType image/icon "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType text/html "access plus 7200 seconds"
ExpiresByType application/xhtml+xml "access plus 7200 seconds"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 week"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\\.(css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</FilesMatch>
<FilesMatch "\\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</FilesMatch>
</IfModule>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.user.website.fr/$1 [R,L]
Options -Indexes
当我访问“user.website.fr”时,css 和图像不会加载到我的“index.php”页面(404 错误)。我已经检查了很多次路径,并且对“共享”文件夹没有特殊限制,因为我可以使用“DIR”以相同的方式访问“共享”文件夹中我的“config/config.php”文件的内容.我试着打印路径,每次看起来都是正确的,但我仍然有 404 错误。还尝试了相对路径。
我的问题:
1 - 这可能是什么原因造成的?可能是“.htacess”文件吗?
2 - 在这个子域配置中,我需要在每个子域的根目录下有一个“.htaccess”文件吗?
此时我的想法已经用完了......