我有example.com
域并设置为cloudflare。
但是有些时候我不需要使用cloudflare,所以我创建了up.example.com
子域并且没有使用cloudflare。然后我把它停在主域。
这意味着example.com
和up.example.com
指向根网站。
现在,为了覆盖SEO中的重复内容,我需要一个.htaccess
文件。
这些项目对我很重要:
upload
控制器的所有地址。例如:up.example.com/upload / 为此,我在这里写一个代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^up\..+ [NC]
RewriteCond %{REQUEST_URI} !^(/upload/?[a-z,A-Z,0-9]*)$ [NC]
RewriteRule . - [R=404,L,NS]
# Hide index.php , this used for YII PHP Framework
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]
但是在这段代码中我的问题是:
Not Found. The requested URL /index.php was not found on this server.
,但必须打开它。注意:关于其他网址,我得到了正确的404错误,例如up.example.com/upload/test.jpg我收到Not Found. The requested URL /upload/test.jpg was not found on this server.
错误消息,此错误消息指向/upload/test.jpg
但是大约up.example.com/upload/test
错误消息指向index.php
文件!
请帮我修正.htaccess
代码。
答案 0 :(得分:0)
我在this link的帮助下解决了这个问题
只需使用!^index\.php$
代替.
更正码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^up\. [NC]
RewriteCond %{THE_REQUEST} \s/+index\.php[?\s] [NC]
RewriteRule ^index\.php$ - [R=404,L,NC]
RewriteCond %{HTTP_HOST} ^up\. [NC]
RewriteCond %{REQUEST_URI} !^(/upload/?[a-z,A-Z,0-9]*)$ [NC]
RewriteRule !^index\.php$ - [R=404,L,NC]
# Hide index.php , this used for YII PHP Framework
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]