htaccess, rewriteurl to page of WordPress site in sub-folder - wordpress

Here's the scenario, I have a single server and two WordPress sites living in their respective sub-folders:
public_html/site_one/
public_html/site_two/
These sites display as follows:
www.site.com/site_one/
www.site.com/site_two/
The second of those sites has a splash page / landing page:
www.site.com/site_two/landing-page/
...that needs to display in the root of the site:
www.site.com/
I'm aware that there are better ways of achieving this, but I'm restricted to working with how it's currently set up.
Initially I thought I would be able to set up a .htaccess file in the root that rewrites access to the root of the site to display the landing page from site_two, but this isn't working as expected. This is the .htaccess file from the root of the server:
RewriteRule ^$ subfolder/page-slug [L]
This redirects to the site's front page. If I replace page-slug with ?p=1234 then it displays as the correct page but also seems to redirect to the landing page's full URL.
Is there any means of achieving what I'm after?
To clarify:
User visits site.com
URL displays as site.com
Page displayed is site.com/site_two/landing-page/
I've managed to have this behaviour working when not linking to a WordPress page (using a test index.php in 'test-subfolder') but WordPress and its own .htaccess file seems to be confusing matters.
Any help would be appreciated. Is there a way of excluding the landing page from the WP .htaccess file and what is it about the WP .htaccess file that's stopping the page being displayed at the root of the site?

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.

Change only the home URL in my WordPress site

I have a WordPress website and the home page is configured to be the latest posts
What I want is that only the homepage URL that is, e.g. www.test.com redirects to subdomain.test.com and when the user needs to visit the older homepage will only access through test.com/home.
I need this because we will start a campaign in a landing page (subdomain.test.com) today.
But this is only for a few days, it is not a permanent change. How can I achieve this?
you can create a new page in WP where you can redirect to your sub domain.
OR
you can do this to make some changes in .htaccess file
RedirectMatch 301 ^/$ http://newsite.com.in/
add this in .htaccess file

How to set default index to launch first.html but allow root / to still work?

I have to set a temporary html splash page, but ensure all links remain the same.
Hence the root / still launches the Wordpress home page but the fist page shown when users hit the site will be first.html
Can anyone provide ways of doing this via htaccess or any other way?
The site is running in an Apache environment with CPanel.
You can use this in your .htaccess to set the default index page
DirectoryIndex first.html
But then how are you going to get to your wordpress site after that shows? You'd have to use some type of Javascript redirect or meta refresh and modify your .htaccess rules. If I was going to do something like this, I'd use a plugin that is designed to have a splash screen and then show the site. There seems to be several usable ones.
https://wordpress.org/plugins/search.php?q=splash
I finally figured it out, so in case this helps anyone else...
I added this to my .htaccess file:
DirectoryIndex first.html index.html index.php
Then in my functions.php file I added the line:
remove_filter('template_redirect', 'redirect_canonical');
The above line allows the Wordpress front page to run from /index.php
If this line is missing then the index.php page keeps redirecting back to / and displaying first.html
Now the home page and site can stay where it was without modifying any configuration settings and the permalinks can remain unchanged.
When we no longer want the first.html to display, we remove the line in the htaccess and the filter call.

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.

Why is a static html page loading instead of Wordpress?

I have WordPress installed in my main directory for my website and not in /wordpress. Currently my htaccess file has in it DirectoryIndex index2.html. This points to a static html page that was my landing page before installing wordpress. Now, when I visit my site after having installed WordPress I am still presented with the same landing page as before. What do I need to change to make sure that going to my domain will now point to the PHP pages of WordPress instead of my old html content? The site is on a shared Window hosting plan if that makes any difference
Make sure that you do not have an index.html file in your root WP directory. index.html files have precedence over the index.php files. That explains why the landing page is loading even when you navigate to a subpage of the site.
Just comment this line or change it to
DirectoryIndex index.php

Resources