0

I have a domain (say example.com). There is a folder in root named freesites. For each subfolder of freesites (say sf) I add a subdomain (sf.example.com). In each subfolder there is a separate web application started with index.php file.

root (example.com)
|-- index.php
|-- .htaccess
|-- ...
|-- freesites
  |-- sf1 (sf1.example.com)
    |-- index.php
    |-- ...
  |-- sf2 (sf2.example.com)
    |-- index.php
    |-- ...
  |-- sf3 (sf3.example.com)
    |-- index.php
    |-- ...

The problem: I don't want visitors to send requests as example.com/freesites/sf1/blabla. it doesn't work. I wish to redirect these requests to sf1.example.com/blabla. Furthermore I like to ban crawlers to do this type of requests.
What code I need in .htaccess and robots.txt?
Note: I redirected www to non-www in .htaccess now.

Edit1: .htaccess content is

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteBase /
RewriteRule ^freesites/([^/]+)/(.*)$ http://$1.example.com/$2 [R,L]
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

and it doesn't work

4

1 回答 1

0

与往常一样,如果我在下面的(未经测试的)代码中使用的内容不清楚,请参阅文档:

RewriteRule ^freesites/([^/]+)/(.*)$ http://$1.example.com/$2 [R,L]

如果这些 url 是从某个地方链接的,爬虫 - 可能会抓取这些 url,但它们也应该遵循重定向并只保存“好”的 url。

于 2013-11-02T21:18:06.450 回答