Routing for Wordpress Multisite with both subdomain and subdirectory - wordpress

New to WordPress but finally got close to what i want. What I wanted was to use multisite with both sub domains and sub directories.
What i did:
- I setup wordpress multisite with subdomain option.
- I setup my domainname to allow wildcard subdomains
- I use the standard htaccess file for subdirectories (this fixed a css issue to diaplay sites with both subdomains and subdir correctly)
- After I create a new website I go to edit and add a subdirectorie to the url
The result:
The above steps allowed me to create websites like the list below:
- domain.com
- sub1.domain.com
- sub1.domain.com/en
- domain.com/en
- ...
The problem:
All the websites display correctly, but the admin url for urls that have both sub domain and sub directories doesn't seem to work (eg. "sub1.domain.com/en/wp-admin/").
The solution?:
I think it can easily be fixed in the htaccess, mainly with changes to the standard line below:
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
Does anybody know how to rewrite the above line so the wp-admin can be accessed by domains that have both subdomains and subdirectories? Keep in mind that it also has to work for domains that only have a sub domain or sub directory.

since the above might not be possible I ended up working with the plugin WP Multi Network https://nl-be.wordpress.org/plugins/wp-multi-network/ .
Now I can create a network per subdomain which is also a multisite then i can create subdirectory sites per subdomain. All users are shared across all sites/networks.

Related

Redirecting specific urls to subfolder on same domain

I have moved my phpBB board from dommain.com to domain.com/forum.
I have launched a Wordpress website on domain.com.
As a consequence, all links to topics on my board end up on a 404 page of my Wordpress website on domain.com
I would like to redirect links to topics on my board.
For example:
Redirect: example.com/viewtopic.php?f=17&t=35
To: example.com/forum/viewtopic.php?f=17&t=35
So only /forum should be added.
Is changing the .htaccess file of my WordPress website the best way to do this? And if so, what would be the correct code?
Of are there better ways (faster/better for SEO) that I don't know of.
Is changing the htaccess file of my Wordpress website the best way to do this?
Implementing this in the root .htaccess file is a reasonable way to do this, unless you have access to the main server config. Alternatively, you could perform this redirect in PHP (in WordPress), but that puts the burden on your WordPress site.
For example, at the top of your root .htaccess file, before the existing WordPress directives (ie. before # BEGIN WordPress) try the following:
# Redirect old forum topics to "/forum" subdirectory
RewriteRule ^viewtopic\.php$ /forum/$0 [R=301,L]
Any query string is passed through by default. So, a request for /viewtopic.php?<something> is redirected to /forum/viewtopic.php?<something>.
The $0 backreference contains the URL-path matched by the entire RewriteRule pattern. ie. "viewtopic.php" (this simply saves repetition).
NB: You should test first with a 302 (temporary) redirect to avoid potential caching issues.

Sub-domain as sub-directory in URL

We need solution for our new server, we have one main domain e.g. example.com and its hosted on VPS this website is in ASP.Net with blog e.g. example.com/blog , The blog is in sub-directory and using Wordpress. We got new server and we want to move our blog on new VPS so we created sub-domain on main domain e.g. blog.example.com and change the A Record in control panel and blog.example.com is working fine, but we want to show URL like this example.com/blog/ is there a any way we can show sub-domain as a sub-directory ? The main website will remain host on main server we only need to work with sub-domain. So it shows all links like, example.com/blog/post-name/
Try this in your .htaccess:
RewriteEngine On
RewriteRule ^blog/(.*) http://blog.example.com/$1 [P,L]
It uses mod_proxy (and will fail if it's not available) to reverse proxy the traffic beneath /blog/. Obviously, if you have a lot of traffic or bad connection between the two servers, you will want something that does cache, but usually works quite good.
You will probably have to set
define('WP_HOME', 'http://example.com/blog');
define('WP_SITEURL', 'http://example.com/blog');
in your wp-config.php so the internal links point to the URL you want them to work as.

Redirect sub domain to main domain without effecting sub folders with .htaccess

My situation is as follows:
I've have a new website at my main domain. Example: mywebsite.com.
My old portfolio is located at an old sub domain: portfolio.mywebsite.com.
All portfolio items can be found in a sub directory at the portfolio site.
So portfolio item 1 can be found at portfolio.mywebsite.com/item-1, etc.
The sub domain is running WordPress with Multisite enabled.
The sub domain and main domain are hosted by different web hosts.
I want to redirect all traffic from portfolio.mywebsite.com to mywebsite.com/portfolio. But I don't want to redirect traffic from the portfolio items, since I don't have time to build a new portfolio yet. Therefor I also need to be able to acces the wp-admin folder on the sub domain.
In short: How do I redirect traffic from portfolio.mywebsite.com to mywebsite.com/portfolio without effecting all the other urls? :)
Best regards,
Michael
If i understand well your problem i think that you can use a simple plugin for redirection like Safe Redirect Manager
It's very simple to use.
Try placing this redirect rule in root of portfolio.mywebsite.com as very first rule:
RewriteEngine On
RewriteRule ^([^/]+)/?$ http://mywebsite.com/portfolio [L,NE,R=302]

how to block auto created subdomains from search engines which has another domain name?

I have hosted the BBBB.COM site in a shared hosting server, which has a root domain called as AAAA.COM, which is a wordpress site. So, my site folder is located at AAAA.COM/BBBB, which is not accessible directly nor by search engines.
My problem is - there is a subdomain created automatically, when I checked through cpanel, where it shows BBBB.AAAA.COM as a subdomain, which might be normal for a hosting server.
However, all my contents from BBBB.COM are indexed in Google search. When I click one of the search results, it shows BBBB.AAAA.COM as the URL in address bar, but shows everything from BBBB.COM.
I am not able to remove AAAA.BBBB.COM subdomain from CPanel as it shows that the subdomain has a link with the domain BBBB.COM.
I can't even block search engines from accessing the subdomain, as I have to use this code in robots.txt placed in subdomain:
User-Agent: *
Disallow: /
And this code in htaccess file of the root domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^robots.txt$ robots_no.txt
But, If I place the robot.txt with Disallow tag in BBBB.COM, then the whole BBBB.COM site will be deindexed by search engine.
Can I solve this or Do I have to contact the Hosting support?

htaccess Mod rewrite and permalink

I have a WordPress website where the requirement is exactly like below:
WordPress site should be installed on: http://www.mydomain.com/wp/ |
Website homepage should be access from: http://www.mydomain.com/ if someone visits http://www.mydomain.com/wp/ he should be redirect to http://www.mydomain.com/
But when accessing all other inner pages, visitors should follow the URL format:
http://www.mydomain.com/wp/test-page1
http://www.mydomain.com/wp/test-page1
This means I need the main website access from main domain directly but all other inner pages should open under sub-directory as mentioned above.
how can I do that with .htaccess? Thanks
Please look into this website about htaccess redirects: http://htaccess.wordpress.com/2008/09/15/redirecting-urls-in-htaccess/
Aside from that, you will want to have your RewriteBase to be / and not wp so that the user doesn't go to wp subfolder automatically.

Resources