I have example.com
domain and set on cloudflare. But some time I don't need to use cloudflare, so I create up.example.com
subdomain and unused of cloudflare for it. then I park it on main domain. That means the example.com
and up.example.com
point to root site. Now for cover duplicate content in SEO, I need to a .htaccess
file.
These items is important for me:
upload
controller must be accessible from subdomain. for example: up.example.com/upload/ For this, I write a code here:
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]
But in this code my problem is:
Not Found. The requested URL /index.php was not found on this server.
Not Found. The requested URL /index.php was not found on this server.
, but must open it. Note: about another URLs I get correct 404 error, for example for up.example.com/upload/test.jpg I get Not Found. The requested URL /upload/test.jpg was not found on this server.
Not Found. The requested URL /upload/test.jpg was not found on this server.
error message, in this error message pointed exactly to /upload/test.jpg
but about up.example.com/upload/test
in error message pointed to index.php
file!
Please assist me to have correction .htaccess
code.
I resolve this problem with help in this link .
Just must use !^index\\.php$
instead .
correction code:
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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.