Redirecting Subdirectory to Subdomain with htaccess

后端 未结 5 1539
再見小時候
再見小時候 2021-01-06 09:38

I\'m relatively new to using .htaccess, and have never done any coding besides what I\'ve read online. I\'m using Bluehost, and I\'d like to redirect my blog subdirectory t

相关标签:
5条回答
  • 2021-01-06 09:46

    RewriteCond %{HTTP_HOST} ^check.domain.info$

    RewriteCond %{REQUEST_URI} !^/check/

    RewriteRule (.*) /check/$1

    0 讨论(0)
  • 2021-01-06 09:47

    Have you tried this one?

    RewriteEngine on
    RewriteBase /
    RewriteRule ^/blog/(.*)$ http://blog.subdomain.com/$1 [R=301,L]
    
    0 讨论(0)
  • 2021-01-06 09:50

    A lot of web hosts today provide an easy implemention for subdomain creation in their administration panels. You just need to to go there, choose you subdomain name, and then point it to a directory in your tree.

    If you can't, then it will be a little more complicated (You will need to resolve that subdomain to your server ip, configure some virtual hosts ... etc) and you may not have enough privileges to do that (unless you are on a dedicated server).

    Edit 2

    To redirect requests to www.example.com/blog to blog.example.com, try this :

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
    RewriteRule ^blog/(.*)$ http://blog.example.com/$1 [L,QSA,R=301]
    
    RewriteCond %{HTTP_HOST} ^blog\.example\.com$
    RewriteCond %{REQUEST_URI} !^blog/
    RewriteRule ^(.*)$ /blog/$1 [L,QSA]
    
    0 讨论(0)
  • 2021-01-06 09:50

    To redirect subdomain1 and subdomain2 and directory3 to a directory with HTTPS://, I use the following code:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^subdomain1.example.com [OR]
    RewriteCond %{HTTP_HOST} ^subdomain2.example.com [OR]
    RewriteCond %{HTTP_HOST} ^example\.com/subdomain3 [NC]
    RewriteRule ^(.*)$ https://example.com/subdirectory/$1 [R=301,L]
    
    0 讨论(0)
  • 2021-01-06 09:54

    I wanted to add my two cents,

    1) to answer the question above, this rewrite should fix it:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !\.
    RewriteRule ^/blog$ http://blog.example.com [R=302,L]
    

    2) but, I think this is not enough by itself, you also need to change DNS, so that blog.example.com is pointed at the right server, and this can be done by a cname similar to this:

    blog.example.com  CNAME example.com TTL 1080
    

    (not exactly how it will look, but use your DNS webinterface to set this up).

    0 讨论(0)
提交回复
热议问题