Mask a forwarded url to wordpress in a directory - wordpress

I built a website for a client at clientsite.com. She has a new business and wants a wordpress site. So I installed wordpress in clientsite.com/wordpress. I can't install wordpress in the root because that's where her original site is and I need the wordpress site in its own folder. She has a domain with godaddy called newbusiness.com. I assigned that to bluehost (her host provider) and added it as an addon and now when you go to newbusiness.com you see the pages located at clientsite.com/wordpress, and newbusiness.com in the address bar. Exactly what I want. EXCEPT, when you navigate to any other page on the site, the address bar changes back to clientsite.com/wordpress. Not good.
I'm having a HORRIBLE time trying to figure out how to keep newbusiness.com in the address bar throughout the whole site. Please help!

One really simple solution is to add a few lines to the .htaccess file in your /wordpress folder. This file is created during the installation, so it should be there. It probably contains the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Try adding these 3 lines:
RewriteCond %{HTTP_HOST} !newbusiness.com$ [NC]
RewriteCond %{REQUEST_URI} clientsite\.com/wordpress [NC]
RewriteRule ^(.*)clientsite\.com/wordpress(.*)$ $1newbusiness.com$2 [L,R=301]
right before </IfModule>

Related

Wordpress htaccess not working with subdirectory

i have directoryoffering-pages in my domain
offering-pages/.htaccess code is
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.php [L]
</IfModule>
# END WordPress
i access dashboard of wordpress and only the home page of my website.
when i go to other page like http://domain/offering-pages/offerings-for-students/ it display the content of domain/index.php
Try this script and change domain and subdomain according to their names and also post wordpress related question to wordpress.stackexchange
RewriteEngine On
# rewrite subdomains to separate folder
RewriteRule ^subdomain/ - [L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
RewriteRule ^(.*)$ subdomain/$1 [L]
# or if you want to rewrite sub.domain.com/test to /subdomain/sub/test
#RewriteRule ^(.*)$ subdomain/%1/$1 [L]
# force www
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R]
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.php [L]
# END WordPress
Did you install Wordpress in the offering-pages directory? If so, you need to change index.php to point to your directory where Wordpress is installed.
From:
require(dirname(__FILE__) . '/wp-blog-header.php');
To:
require(dirname(__FILE__) . '/offering-pages/wp-blog-header.php');
SOLVED!!!
The top site's custom Permalinks (anything other than "Plain") clash with the subdirectory site's custom Permalinks (anything other than "Plain").
Both cannot be set to be custom (without a complicated solution).
To fix (and not get "Invalid JSON response" when modifying or creating Posts and Pages), simply delete the top site's .htaccess file (in the root directory usually under public_html).
And to prevent future clashes, go to the top site's site Settings > Permalinks in WordPress and change the setting to Plain, delete any Category and Tag Base, and click SAVE. When you click SAVE, a new .htaccess file is created or the old one is overwritten for that directory (and Plain actually means an empty .htaccess file or no setting).
This means that you won't be creating pages and posts with pretty URLs from the top site (for that specific site you'll have to use an auto-generated post or page url like example.com/?p=123 instead of example.com/postname).
Antonio Robateau

Domain Mapping in WordPress

I have already spent hours on this, and i don't make any progress. How can i mask or map my WordPress page into my sub-domain without re installing the whole WordPress files again? I have tried those multi-site plugins and it gave me a fresh copy of WordPress! I don't want that.
I have also tried the WPMU domain mapping plugin, but the subdomain outputs the homepage.
What i want is:
e.g i want my URL www.mysite.com/mypage to become mypage.mysite.com
Is this even possible? Also, I have already created a wildcard sub-domain in my cPanel.
NOTE* This will be only for 1 page only.
here's my current .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mypage\.domain\.com\.es$
RewriteRule ^(.*)$ http://domain.com.es/mypage/ [L,QSA]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

WordPress htaccess issue with www

I have a WordPress website that is set to direct to www by default. Everything works perfectly, however I have a few sections that are custom coded, to go to "profile" pages of local services, accommodation etc. this works fine in development however on the live server when you access the link via www.example.com/services/example-here/ it redirects to example.com/wp-content/themes/theme-here/custom/services.php?slug=example-here
I've been told by my webhost that it is WordPRess that is causing the issue, however everything says www.example.com/ (siteurl etc.)
Here is the code in the htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^.*services/(.*)/$ /wp-content/themes/theme-here/custom/services.php?slug=$1 [QSA,L]
RewriteRule ^.*accommodation/(.*)/$ /wp-content/themes/theme-here/custom/accommodation.php?slug=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any ideas I've checked all my settings, Could it be a host issue inside of apache conf to do with mod re-write? I also might add that the code works perfectly without the www's added but my client requires the www.
Add a www forcing rule on top of this .htaccess just below RewriteBase / line:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
Make sure in your permalink settings of WP you have blog address with www

Modifying wordpress htaccess to forward certain urls to subdirectory

For whatever reason or another I haven't been able to ascertain, my company has decided to go with wordpress for one of their websites. They asked me to build an affiliate application on the same domain, which I did. Everything works great with the exception of this dilemma:
wordpress is installed in the root directory. All pages, videos, sales, etc are made from within wordpress pages.
The affiliate application is in a subdirectory /aff/ and affiliates' pages are found at mydomain.com/aff/index.php?aff=affiliateusername
Affiliates (and their leads) should be able to load their pages simply by typing in www.mydomain.com/affiliateusername but I am struggling to understand how to translate wordpress htaccess rules to do this.
Obviously the best order in which to have this work is for wordpress to first determine if there are any blogs/posts/pages that match the url term FIRST, and if none is found, then to redirect all else to www.mydomain.com/aff/index.php?aff=whatever
Here's what I was finally able to come up with that works for the index page and for the affiliate pages, but does not correctly load any wordpress pages other than index.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(images|wp-admin|wp-content|wp-includes|go|compliance\.html)($|/) - [L]
#RewriteRule ^([^/].*)$ /aff/index.php?aff=$1 [R,L]
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You can tell I've attempted to exclude certain directories from the rewrite but have not been successful. I've read other advice via Googling, to put the redirect rules ahead of the wordpress block, but there are few issues. When I put this line ahead of the # BEGIN WordPress line, I get an endless redirect loop which keeps going to /aff/index.php?aff=aff/index.php?... etc (this is the same line I use for the same affiliate application on a different, wordpress-free, domain)
#RewriteRule ^([^/].*)$ http://www.mydomain.com/aff/index.php?aff=$1 [L]
I feel like I'm missing something terribly obvious. Should I just be setting up wordpress to redirect all 404's to /aff/index.php?aff=originalrequest? How would I go about doing that?
Thanks in advance.
You are using RewriteRules incorrectly in place of RewriteConds. Adding them in between the WordPress rules is surely breaking your blog as well. Change your .htaccess code to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ /aff/index.php?aff=$1 [R=301,QSA,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
If you want the URL to stay mydomain.com/affiliate remove the [R] and use only [QSA,L]. I've updated the rules above to show how to exclude a path from affiliate redirection. The following
RewriteCond %{REQUEST_URI} !^/blog\b
excludes all URLs pointing to /blog or its sub-directories /blog/sub/dirs from redirection. If there are root-level .php pages present (even if they are few) the exclusion can more easily be handled by changing the rule to
RewriteRule ^([^/.]+)$ /aff/index.php?aff=$1 [R=301,QSA,L]
assuming that a . and a / can never be present in an affiliate name.

htaccess WordPress and separate directory without filenames

On a site I'm working on the main portion of the site is wordpress powered.
I've added another directory completely separate from the wordpress site called employees and I'm having a little issue with the mod_rewrites for the new directory.
obviously wordpress uses this code to make its pretty urls
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
# END WordPress
but I want to add this rule as well and any other necessary rules or conditions so that all of the /name.php files in the employees directory get redirected to just /name
RewriteRule ^employees/(.*)$ employees/$1.php [L,QSA]
The several things I've tried all just cause employees/main to 404 but employees/main.php resolves properly.

Resources