admin管理员组

文章数量:1316307

I have a subdomain

I would like to redirect it to subdirectory as

But not admin(/wp-admin). Admin area should be as it is

currently I have this in my htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]

    RewriteCond %{HTTP:X-Forwarded-Host}i ^example\ 
    RewriteCond %{HTTP_HOST} ^blog\.example\$  
    RewriteRule ^/?(.*)$ /$1 [L,R=301,NC]

    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTPS} off
    RewriteRule ^/?(.*)$ /$1 [L,R=301,NC]
</IfModule>

and my site URL and WordPress URL is:

WordPress Address (URL)   = /blog 
Site Address (URL)        = 

but this setup redirects every URLs in my website and creating many issues in the backend.

What is the best ways to do this?

I have a subdomain

http://blog.example

I would like to redirect it to subdirectory as

https://www.example/blog

But not admin(/wp-admin). Admin area should be as it is

http://blog.example/wp-admin

currently I have this in my htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]

    RewriteCond %{HTTP:X-Forwarded-Host}i ^example\ 
    RewriteCond %{HTTP_HOST} ^blog\.example\$  
    RewriteRule ^/?(.*)$ https://www.example/blog/$1 [L,R=301,NC]

    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTPS} off
    RewriteRule ^/?(.*)$ https://www.example/blog/$1 [L,R=301,NC]
</IfModule>

and my site URL and WordPress URL is:

WordPress Address (URL)   = /blog 
Site Address (URL)        = https://www.example/blog

but this setup redirects every URLs in my website and creating many issues in the backend.

What is the best ways to do this?

Share Improve this question edited Sep 7, 2020 at 19:21 Jesse Nickles 7357 silver badges19 bronze badges asked Apr 2, 2017 at 8:06 Muhammad RiyazMuhammad Riyaz 1482 silver badges13 bronze badges 1
  • That won't be easy. You have a lot of files in other folders such as wp-includes that are loaded both in admin and front end. – Johansson Commented Apr 2, 2017 at 16:35
Add a comment  | 

2 Answers 2

Reset to default 2

Use below rule,

RewriteEngine On

# excluding www
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^blog

# excluding wp-admin
RewriteCond %{REQUEST_URI} !^wp-admin
RewriteRule ^ https://www.example/%1

Have you tried the following?

<html>
    <head>
        <meta http-equiv="refresh" content="0; url=https://www.example/blog" />
    </head>
</html>

This would be your index.php file, and you would place it in http://blog.example

Note The 0 in the refresh statement is the number of seconds your page waits before redirecting to a new site, and 0 means redirect immediately.

Note 2 You can make a new theme, that only contains this index.php file above (and the style.css file for theme definition), and switch to this theme, and you will be set. Alternatively, update your existing theme, and add the meta tag above to your header. Either way should work.

本文标签: htaccessHow to redirect the frontend of a WordPress site (only)