You shouldn’t need to add anything to .htaccess
. Assuming your subdomain points to the same place on the filesystem as the main domain then you need to configure WP to accept requests to both hostnames (to prevent a canonical redirect – which is what I assume you were experiencing?).
In other words, instead of hardcoding the domain name in WordPress (WP_SITEURL
and WP_HOME
), you need to make this dynamic based on the requested hostname.
For example, in wp-config.php
set the following:
define('WP_SITEURL','https://'.$_SERVER['HTTP_HOST']);
define('WP_HOME','https://'.$_SERVER['HTTP_HOST']);
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ RewriteRule ^(.*)$ http://example.com [P]
This is attempting to “proxy” the request from the subdomain to your main domain – using your server as a reverse proxy. This requires access to your server config to configure (properly).
Related Posts:
- WordPress 404 on Subdomain
- Access sub-domain when root public_html is protected with .htaccess password
- Configure .htaccess to have a WordPress single site installation with all subdomains pointing to the same pages?
- Htaccess for Wordpess set on single subdomain
- Rewrite /?rest_route=/ link to /wp-json/ without changing default permalink structure in apache
- index.php not loading in main folder of wordpress
- Create subdomain masking for each user in WordPress
- Redirect from different port to subdomain – htaccess
- Only expose routes with prefix /wp-json on WordPress using Apache
- WildCard SSL with wordpress subdomain
- What’s the opposite of required valid user in .htaccess authentication
- How can i redirect one url to another url using .htaccess or add_rewrite_rule
- Override htacces rule only for specific directory
- Restrict uploaded files into a custom folder to logged in users by htaccess: looking for Nginx – not only Apache – solution
- How do I test to ensure that my wp-config file is protected?
- .htaccess Security Header Rules
- mod_rewrite loop, redirecting http to https on certain section of wordpress blog
- .htaccess in subdir gets ignored by WordPress’ own .htaccess in /
- WordPress – Promoting A Dev Build In A Subdirectory To Production / Root Directory
- Redirect old domain with query paramaters
- Does WP suppresses .htaccess if permalinks are disabled?
- fix 302 redirection error on https
- Redirect all subdomains to root domain
- Accepting special characters in querystring
- WordPress permalinks confusion
- How to use slug with subdomain?
- Unable leverage Browser Caching on AWS Bitnami stack (Apache) through W3TC and Cloudfront CDN
- How to move wordpress website from hosting account to localhost
- How to block wordpress admin by htaccess
- I can access subdirectory, but not files within it
- In a subdomain network, what .htaccess settings can I use to have WP ignore requests to one subdomain?
- .htaccess for Subdomain and Subfolder w/SSL
- WordPress redirection
- How To Add CSP frame ancestors in WordPress Website? [closed]
- Subfolder install not working
- Browser Caching .htaccess
- Getting a 500 Internal Server Error on Laravel 5+ Ubuntu 14.04
- .htaccess: Invalid command ‘RewriteEngine’, perhaps misspelled or defined by a module not included in the server configuration
- htaccess problem after saving Settings
- Multisite htaccess on localhost with WP as an SVN external?
- File and directory permissions
- htaccess https redirect from www to non-www
- Name-based virtual host configuration in Apache seems to cause a “500 Internal Server Error”
- WordPress Multisite – Multiple subfolders for blogs
- Isolating WordPress to a subfolder
- Error 101 after upgrading WordPress
- Error:406 not acceptable
- What is the role of .htaccess file in WordPress?
- Remove File Extension for Page Outside of WordPress
- different child theme for subdomain
- How do I edit the htaccess file to optimize my website?
- Block only external access to wp-cron.php on OpenLiteSpeed
- Site searches by Python for non-existent assets
- WordPress On subfolder
- How To Allow Only Specific User Agent To Access a URL?
- How to ignore folder in site root while accessing a URL
- How can I enable keep alive (Not accessing to Apache)
- Site loads very slowly (4-5 minute load time)
- HTTP sitewide, except for: wp-admin, and 2 custom directories
- How do I host WordPress on a hidden domain through a reverse proxy?
- WordPress installed in root, need second in subdirectory with different domain
- htaccess has broken my site
- TimThumb & htaccess : clean url
- What to write in the htaccess in order to detect browser language and point accordingly?
- .htaccess RewriteCond excluding directories does not work when there is an .htaccess or php.ini in subdirectory
- Separate 404 page for WordPress in subfolder
- Multisite Subdirectory with same domain subdomain
- Weird behavior of Dashboard, must be core files
- 404 error Additionally 403 Forbidden error on a URL
- Remove trailing slash after .html extension
- Multisite install w/ Sub domains on a subdomain
- I have a page using a pretty url and a mod_rewrite rule matching it. I expected it to give an error but it’s working. Why?
- How do I setup htaccess for 301 redirects, post Joomla to WordPress migration? [closed]
- How to use different domains for different blogs hosted in the same host in subdomains with .htaccess
- Hide a subdirectory on my website hosting
- Can’t access WP site over WiFi network
- How do I do a redirect to WordPress permalink with post id via htaccess?
- Creating a copy of a website in a subdirectory, wp-admin redirect problem
- I am new in word pres my font awesome is not allow
- htaccess redirect throws an error: PHP Catchable fatal error: Object of class WP_Error could not be converted to string
- How do I reset a rewrite?
- Basic Auth .htaccess on wp-login, but allow logout from woocommerce
- Why my WordPress Site Asking for HTTP Authentication?
- htaccess redirects invalid request to home page not 404
- WordPress How to rewrite URL for custom pages
- How to properly give WordPress its own directory
- WordPress permalinks is wrong. It wants me to change my htaccess file. But then site crashes
- Question with .htaccess and wp-login.php prevention
- WordPress RSS feed to external XML
- Does htaccess password keep search engines out?
- What to do after a wrong RewriteRule?
- htaccess old php pages to new wordpress ones
- htaccess mod_rewrite not working
- different CNAME to corresponding subfolders
- block seacrh engines for all pages EXCEPT homepage
- Giving WordPress it’s own directory and using .htaccess Directory Index
- Allowing access to certain WordPress created pages or posts with htaccess / htpasswd
- Restrict download files from not generated Urls
- htaccess – Server Subdirectory With Different Name Than URL Subdirectory
- .htaccess seems to be required but I can not find it