Htaccess - point multiple domain to different path - php

For example I have a domain example.com and server IP of 12.34.56.78
I need to point example.com to a facebook page, then point 12.34.56.78to my root directory where my website files are saved.
Here's my current Htaccess code
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(.*)$ https://www.facebook.com/examplefbpage/
RewriteCond %{HTTP_HOST} ^12.34.56.78$
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Currently, both example.com and 12.34.56.78 redirects to the facebook page.
By the way, my site a created using wordpress.
Thanks in advance!

Related

How to install Wordpress on subfolder (incl. wp-admin)

I have a domain, www.example.com, and I want to install Wordpress (4.7.4) to www.example.com/wordpress/. I'm also behind a nginx reverse-proxy, but not sure if that's relevant.
The following .htaccess does not work, ie. a GET request to www.example.com/wordpress/ redirects to www.example.com/wp-admin/install.php. I need the entire install to live on /wordpress/ subfolder, ie. www.example.com/wordpress/wp-admin/install.phpetc.
How can I configure this?
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ wp/$1 [L]
RewriteRule . /wordpress/index.php [L]
create "wordpress" directory in your domain root folder & then add .htaccess as mentioned below.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress

WordPress MultiSite Redirect

A large multi-network wordpress site is auto directing users to the root domain.
Everytime I go to http://sitename.com/username/wp-admin it looks like this:
http://sitename.com/wp-login.php?redirect_to=http%3A%2F%2Fsitename.com%2Fwp-admin%2F&reauth=1
Here is my .htaccess file
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
I've tried disabling all plugins.

Images are not showing up

I am working on fixing a website.
Images don't show up unless the url starts with www
For example when you try to access this image http://example.com/wp-content/uploads/2013/11/VictorMoreTrimed.jpg, it redirects you to the home page.
With the www in front, it shows up.
I tried to edit the .htaccess file to redirect the whole website to the www version:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com [r=301,nc]
But it still not working.
Can anyone help please ?
Since you provided your entire htaccess, we can try inserting some lines to force www on all your pages.
#DirectoryIndex
index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Insert here to force www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# End of forcing www
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Reference:
How to force “www.” in a generic way?

.htaccess pass request on for /UA/ folder

This is similar to question mod_rewrite: Being redirected to root folder; I want it to stay in sub-folder
but the answer there is not working for me.
I have a main site which redirects via an index.php handler, but I want a pre-live test area which is held in a subdirectory /UA/
I need requests for UA/ to pass through and be handled in the sub directory, I have tried both RewriteRule ^/UA - [L] and RewriteCond %{REQUEST_URI} !^/UA in my .htaccess of the main directory but this hasn't worked. I've tried with/without /'s
Here are my two .htaccess files:
RewriteEngine on
ReWriteBase /
# Redirect to HTTPS site
RewriteCond %{HTTP_HOST} ^my\-site\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.my\-site\.com$
RewriteRule ^/?$ "https\:\/\/www\.mysite\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^/?$ "https\:\/\/www\.mysite\.com\/" [R=301,L]
#Allow UA access
RewriteRule ^/UA - [L]
#Allow certain file types to access directly
RewriteRule \.(css|js|png|jpg|gif|woff|eot|ttf|svg|ico)$ - [L]
# Catch all
RewriteCond %{REQUEST_URI} !^/UA
RewriteRule .* index.php [L]
RewriteEngine on
ReWriteBase /UA/
#Allow certain file types to access directly
RewriteRule \.(css|js|png|jpg|gif|woff|eot|ttf|svg|ico)$ - [L]
# Catch all
RewriteRule .* index.php [L]
The problem is that the site continues to direct to the Live index.php version not the one in /UA/ with a URI of https://www.mysite/UA/
Add this line to always have directory slash on in your root .htaccess:
DirectorySlash On
Keep /UA/.htaccess like this:
RewriteEngine on
ReWriteBase /UA/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|gif|woff|eot|ttf|svg|ico)$ [NC]
RewriteRule ^ index.php [L]

weird automatic wp redirection

When I type the url address of my website with www for example http://www.mayumibeats.com/question it would redirect me to my homepage which is http://mayumibeats.com/ but when i type it without www on it for example http://mayumibeats.com/question it just works fine.
What am I missing here?
Here is my .httaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
NOTE: The site is wpmu
Try changing site URL and home URL, replace http://mayumibeats.com with http://www.mayumibeats.com

Categories