I am trying to create virtual subdomains using .htaccess and wordpress.
But it won't seem to work properly. Using wordpress I get urls like:
foo.eu/test-pagina/?lang=fr
I managed to rewrite this to what i want:
fr.foo.eu/test-pagina/
But when this url is rewritten the page returns an 500 internal server error.
I also made a wildcard for the subdomains in my dns configuration.
Do I have to make subfolders for each subdomain in my root ?
My current .htaccess code is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^([a-z]{2})\.hypnose\.eu$ [NC]
RewriteCond %{THE_REQUEST} \ /+([^\?]*)\?lang=([a-z]{2})&?([^\ ]*)
#RewriteRule ^ http://%2.hypnose.eu/%1?%3 [L,R]
RewriteCond %{QUERY_STRING} !(^|&)lang=
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.hypnose\.eu$ [NC]
RewriteRule ^(.*)$ /$1?lang=%1 [L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Can anyone tell me what did I do wrong?
Have you added "fr" as your subdomain in the domain's control panel?
Add this in your htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/test-pagina/%1/$1 [L,NC,QSA]
Related
I created a website few days back with a url http://abctest.com in wordpress. Now the website has been published to a domain http://www.bcdefg.com.
The server is same, I have not migrated the site, only the domain has been pointed to the same server. I have changed the wphome and wpsite url to respective domain.
What I want to achieve is to redirect all http://abctest.com or http://www.abctest.com requests to http://www.bcdefg.com.
I tried to use .htaccess redirection but that leads to Too many redirection error. Any solution ?
Below is my htaccess code.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !bcdefg.com$ [NC]
RewriteRule ^(.*)$ http://www.bcdefg.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Error is on your rewriteCond : your host is www.bcdef.com and not bcdef.com (www is important)
try replacing this
RewriteCond %{HTTP_HOST} !bcdefg.com$ [NC]
by this :
RewriteCond %{HTTP_HOST} !www.bcdefg.com$ [NC]
I have a wildcard ssl installed on my account (My host is Bluehost) and I followed the directions here from Bluehost's site to install the wildcard SSL. However, when I try and access the site at all it comes up with a 500 internal server error. I am using laravel framework right now for the subdomain, I don't know if that changes anything, but here is the .htaccess file for the main site (Which is a wordpress site):
# Custom subdomain .htaccess SSL + WordPress
RewriteCond %{HTTP_HOST} ^admin.mysite.com$
RewriteCond %{REQUEST_URI} !^/admin/public/
RewriteRule ^(.*)$ /admin/public/$1
RewriteCond %{HTTP_HOST} ^admin.mysite.com$
RewriteRule ^(/)?$ admin/public/index.php [L]
# End custom subdomain .htaccess
# BEGIN WordPress
AddHandler application/x-httpd-php70s .php
<IfModule mod_rewrite.c>
# Custom maindomain .htaccess WordPress
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# End custom maindomain .htaccess
</IfModule>
# END WordPress
And here is the .htaccess file for the subdomain (the one with laravel installed):
<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>
Keep in mind too, I know nothing about .htaccess or how it works, I just did what the webpage said to do.
I suggest you to try below code for simple redirection HTTP to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This should work for your main domain and its sub-domain both. Now if you want to redirect Non-WWW domain to WWW then try below code;
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.domainname.com%{REQUEST_URI} [L,R=301]
We have a Wordpress Mutlisite running so I need do redirect the specific pages, categories and files only if a specific domain is requestet.
So when domain.de/allgemein is requestet it shoul redirect to domain.de/neues-von-der-domain but no if for example domain2.de/allgemein is requestet.
We use Domainmapping so all Domains have just one htaccess file.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.de$ [NC]
RewriteCond %{REQUEST_URI} !^/allgemein
RewriteRule domain.de/neues-von-der-domain/ [NC,L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com [NC]
RewriteRule ^(.*)$ http://otherdomain.com/$1 [R=301,L]
Can also be used to redirect to a landing page based on the requested domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com
Rewriterule ^(.*)$ http://www.any-domain.com/landing-page.html [L]
enter code here <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
put this code in your .htaccess file
I'm trying to run a site that routes all URI requests through an index.php file for processing, but I'm also trying to run Wordpress at the webroot. Everything works fine, except for requests to https://mysite.com/wp-admin/, which gives me a "This webpage has a redirect loop" error. Going to https://mysite.com/wp-admin/edit.php works fine.
My .htaccess file looks like this:
RewriteEngine On
# eliminate www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# force SSL
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}/%1 [R,L]
RewriteBase /
# rewrite directory patterns
RewriteRule ^([a-zA-Z0-9-\/]+)/([a-zA-Z0-9-%/\/]+)/([0-9]+)$ /index.php?page=$1&action=$2&id=$3 [NC,QSA,L]
RewriteRule ^([a-zA-Z0-9-\/]+)/([a-zA-Z0-9-%/\/]+)$ /index.php?page=$1&action=$2 [NC,QSA,L]
RewriteRule ^([a-zA-Z0-9-\/]+)$ /index.php?page=$1 [NC,QSA,L]
# Wordpress
<IfModule mod_rewrite.c>
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any ideas what's causing the redirect loop? I've tried putting
RewriteCond %{REQUEST_URI} !wp-admin
in front of the force SSL and eliminate www rules, but it doesn't seem to make a difference
RewriteRule ^wp-admin - [L]
Add this rule at the top, above all other rules.
I want to redirect directory /api/ and everything after it to HTTPS. Everything else must redirect to HTTP if a visitor tries to visit something with HTTPS.
I'd like WordPress to ignore the /api/ directory (and everything after it) from the current mod rewrite.
This is my current standard WordPress .htaccess:
# 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
Have you tried adding :
RewriteCond %{REQUEST_URI} YourFolderName
RewriteRule ^(.*)$ https://www.example.com/YourFolderName /$1 [R,L]
(Taken from HERE for more info)
Try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/api/ [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]