XF 2.1 How do I redirect all mydomain.com to mydomain.com/forums?

gogo

Well-known member
There's nothing in mydomain.com, yet.

Also is URL redirection the right thing to do, especially regarding SEO? Thanks.
 
Are you planning anything for mydomain.com soon?

You can do this but you won't be able to access anything (via browsers) in the root folder as long as these redirects are in place:

Code:
RewriteEngine on
RewriteBase /

# Rewrites all URLS without forums in them
RewriteCond %{REQUEST_URI} !^/forums/ [nc]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /forums/$1 [L]

If the URL already contains /forums/ this leaves those alone to avoid redirect loops. Anything else is redirected to the /forums subdirectory.
 
OK. I always have to play a bit with redirects for different servers yo get them to work correctly.

First, I am assuming you are using Apache, not nginx. Is that correct?

Second, I assume you are using either WHM/cPanel file manager or a text editor like Notepad++, not notepad.exe. Also correct?

Third, below I am ssuming your forum is at https:// not http:// - if that's incoprect

Try this:
Code:
RewriteEngine on
# This isn't always needed Remove the # if it still doesn't work abnd try that
# RewriteBase /

RewriteCond %{HTTP_HOST} ^mydomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteRule ^(.*)$ "https\:\/\/mydomain\.com\/forums\/$1" [R=301,L]

# if needed, add for SSL if non-https is requested
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
Back
Top Bottom