I have asked my domain host provider to point a website to my public_html folder. but now I have been told the if I need this other domain to redirect to a particular url on my primary domain website, I would need to do it in the htaccess file. At the moment I have researched and this is what my htaccess looks like without any luck!
# Switch rewrite engine off in case this was installed under HostPay.
RewriteEngine Off
SetEnv DEFAULT_PHP_VERSION 5
DirectoryIndex index.cgi index.php
# 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
RewriteCond %{HTTP_HOST} ^otherdomain.org.uk
RewriteRule ^(.*)$ http://www.primarydomain.org/blog/$1 [R=permanent,L]
The above does not redirect my otherdomain.org.uk to the blog page on my primarydomain.org/blog. Please note that my primarydomain.org/blog is a wordpress website page.
Keep redirect rules before your WP rules.
Have your rules like this:
# Switch rewrite engine off in case this was installed under HostPay.
RewriteEngine Off
SetEnv DEFAULT_PHP_VERSION 5
DirectoryIndex index.cgi index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^otherdomain.org.uk
RewriteRule ^(.*)$ http://www.primarydomain.org/blog/$1 [R=permanent,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Related
My problem is the following: My company shares hosting with others, and we have the subdomain inside a "public_html" folder. I can enter the index of my page perfectly, that is in www.principal.com/mypage it enters perfectly.
The problem is when I redirect to pages within my subdomain, they redirect to the 404 Not Found of the main page, that is to say www.principal.com/mypage/new 404 Not Found page of principal.com
The main / public_html / .htaccess file is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
The file public_html/mypage/.htaccess is
<FilesMatch ".(phtml|php|PhP|php5|suspected)$">
Order Allow,Deny
Allow from all
</FilesMatch>
The file public_html/mypage/public/.htaccess is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I must clarify that my subdomain worked perfectly until a few days ago, since March that it worked very well.
Wordpress is the main page of the domain, my page in the subdomain is with the Laravel framework.
So, I redirect from Laravel to Laravel whit
Route::group([
'middleware' => 'auth'],
function(){
Route::get('/onepage', 'HomeController#one');
Route::get('/twopage', 'HomeController#two');
});
Your problem is because the directives in the root level .htaccess are used even something might be directed to the site in the subfolder. Try something like this in public_html/.htaccess, to exclude requests sent to the subfoler:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_URI} !^/autorizaciones/.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
I solved it
I changed The file public_html/mypage/.htaccess is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /MYPAGE
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
I have a shared Linux hosting on which I want to host 2 website.
In /public_html/ I have hosted example.com and on /public_html/example2/ I have hosted example2.com
.htaccess of example.com
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
# 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
#Custom Error Pages
ErrorDocument 403 https://www.example.com/error-403/
.htaccess of example2.com
# 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
#Custom Error Pages
ErrorDocument 403 http://www.example2.com/error-403/
I want to access both the website separately with www version i.e.
example.com as https://www.example.com/ (has SSL it's in main directory)
example2.com as http://www.example2.com/ (do not have SSL and it in sub directory)
Please Note: I have setup site_url and home_url and above given URL in WordPress General settings.
Problem that I'm facing is
When I access example2.com it is taking me to https://www.example.com/example2/
So after reading this answer, and I changed my .htaccess of example.com to
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# if request is not for the /example2/
RewriteCond %{REQUEST_URI} !^/example2/ [NC]
# otherwise forward it to index.php
RewriteRule . /index.php [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
</IfModule>
# END WordPress
So now example2.com is accessible but permalink is not working so when I try to reset it, it is deleting the content of my example2 .haccess file and redirecting me to https://www.example.com/example2/.
Can any one help me out here?
I also tried this with no luck Configuring WordPress .htaccess to view subfolders.
I think that htaccess for example 2 should be like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /example2
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#Custom Error Pages
ErrorDocument 403 http://www.example2.com/error-403/
I moved my old static site to a subdirectory named old. I also installed WordPress on the root. Now i want to implements a 301 redirect for my old static site. The problem is that i want to redirect http://www.example.com/x to /old/x unless there is a x in the web root (infact i dont want redirect also WordPress articles, pages etc.). I tried with this:
# Map http://www.example.com/x to /old/x unless there is a x in the web root.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/old/
RewriteRule ^(.*)$ /old/$1
#WordPress default .htaccess
# BEGIN s2Member GZIP exclusions
<IfModule rewrite_module>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (^|\?|&)s2member_file_download\=.+ [OR]
RewriteCond %{QUERY_STRING} (^|\?|&)no-gzip\=1
RewriteRule .* - [E=no-gzip:1]
</IfModule>
# END s2Member GZIP exclusions
# 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
It doesnt work, i think there is a sort of conflict.
When I use the following url "http://www.tuto3d.netai.net/wordpress/" in my navigator I access normally my wordpress site but when I use http://www.tuto3d.netai.net/ I get the index of folder instead and a link to wordpress folder. I want to redirect in my .htaccess the http://www.tuto3d.netai.net/ to the "http://www.tuto3d.netai.net/wordpress/"
and this is my my .htaccess
# 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
Thank you in advance
Have this rule in your DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteRule ^$ /wordpress/ [L,R=301]
I have just hosted a wordpress website on godaddy .
I am having a situation .
I have a website www.example.com/cnI want when someone open this page this page should redirect to a sub domain cn.example.com .
I am hosting wordpress app first time kindly do let me know how can I do that .I am Python Guy I don't know about htaccess
I tried using header('location:cn.example.com') in the index.php file but the problem is cn.example.com and example.com/cn both pointed to the same wordpress app . So I am getting problem .
Please help me to figure out this problem .
*Updated Htaccess *
RewriteCond %{REQUEST_URI} ^/_dm/s/ [NC,OR]
RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|png|css|js|txt|ico|pdf|bmp|tif|mp3|wav|wma|asf|mp4|flv|mpg|avi|csv|doc|docx|xls|xlsx|ppt|pptx|zip|rar|tar|gz|dmg|iso)$ [NC]
RewriteBase /
RewriteRule ^(.*)$ http://mobile.example.com/ [R,L]
##END MOBILE
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (?!cn.example.com)
RewriteRule ^cn/?$ http://cn.example.com/ [R=301,L]
</IfModule>
<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
# 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
Thanks
Assuming you are letting Wordpress load from the differing hostname, you can handle the rewrite by having the following in your .htaccess file found in the root of your Wordpress install:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (?!cn.example.com)
RewriteRule ^cn/?$ http://cn.example.com/ [R=301,L]
It will match /cn or /cn/ exactly from any host that is not already cn.example.com (prevent looping), and redirect to http://cn.example.com using a 301 HTTP response.
You can test these rules here: http://htaccess.madewithlove.be/