Wildcard subdomains only working with double slash(//) - wordpress

I have created wildcard subdomains based on username. However it is working fine but only issue which occurs it that its working with double slashes at the end. For example johndoe.example.com// and if i use johndoe.example.com/ it redirects me to main domain example.com. I am not sure why this is happening and what to i have to do in .htaccess file. I tried many things in htaccess but it is not working.
Expected URL - username.example.com
Actual URL - example.com/user/username
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ([^.]+)\.example\.com$ [NC]
RewriteRule ^/?$ /user/%1 [L]

Related

URL Rewrite from "bare" domain to specific URL

I need to redirect so when someone types https://mydomain.is to be redirected to https://mydomain.is/issues, I found directive how to do oposite, but not what I want.
mydomain.is is site hosted in plesk.
Desired output:
https://mydomain.is --> https://mydomain.is/issues
Found this guide, but when i click Apply, it shows that web site is about to be deleted
Have you tried using mod_rewrite? For example insert this at the beginning of your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.is$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.is$
RewriteCond %{REQUEST_URI} !^/issues
RewriteRule (.*)$ /issues/$1

Add Subdomain to Wordpress main site

So my main domain is build on the wordpress platform. I have build a custom website which is NOT build on a wordpress platform. All I am trying to do is host the site I build on a subdomain. Thus it should look like this:
www.subsomain.maindomain.com
I have uploaded my files to the subdomain folder and all is working.
MY PROBLEM
My site works fine when entering subdomain.maindomain.com i.e. without the www version.
However as soon as I try to redirect my site to www.subdomain.maindomain.com I get a DNS SERVER NOT FOUND error.
So my NON www version works but when I try to run the WWW version it does not work.
What I have done.
Redirect the subdomain to www version in Cpanel (didnt work)
Change the.htaccess file, tried multiple tweaks and changes (didnt work)
I called godaddy the agent told me because the main site runs on wordpress platform I would need to go into the mainsites wordpress database and make changes there for the www version of subdoman to work...? (is this correct, it doesnt make sese to me..?)
Here is my current .htaccess
RewriteEngine on
# Redirect to domain with www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect to another domain: example.com.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule .* http://example.com%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule .* https://example.com%{REQUEST_URI} [R=301,L]
All I want to do is redirect my subdomain to www version Any help appreciated
It doesn't work because www.subsomain.maindomain.com doesn't exist. You have to add a CNAME record in your zone subsomain.maindomain.com the same way you've added the host subdomain to maindomain.com.

.htaccess rediret from 3th level domains to WordPress page and keep the url

I have a bunch of 3th level domains and I need to redirect them to different wordpress page.
I did it with this code in the .htaccess
RewriteCond %{HTTP_HOST} third\.domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/subs-page/ [R=301,L]
and it works, but I need to keep the original url in the address bar. Is that possible?
If these subdomains are folders in the root, you can try this.
RewriteCond %{HTTP_HOST} third\.domain\.com$
RewriteRule ^(.*)$ /subs-page/$1 [L]
Or you can use a Proxy pass using the P flag to keep the URL in the browser. Make sure mod_proxy is enabled.
RewriteCond %{HTTP_HOST} third\.domain\.com$
RewriteRule ^(.*)$ http://www.domain.com/subs-page/$1 [P]

htaccess subdomain redirect and worpdress

After setting up Wordpress to use permalinks (which added some lines to my htaccess file), I got confused how to redirect a subdomain to a subfolder (astro.aspiracoesquimicas.net should redirect to aspiracoesquimicas.net/astro): what I had tried (and worked) before doesn't work anymore:
RewriteCond %{HTTP_HOST} ^astro\.aspiracoesquimicas\.net$
RewriteCond %{REQUEST_URI} !^/astro/
RewriteRule (.*) /astro/$1
Now I get a 500 Internal Server Error with the subdomain. I don't know about htaccess configuring and don't understand what changed because of Wordpress.
I'd also like to redirect blog.aspiracoesquimicas.net to the main domain aspiracoesquimicas.net
How can I do it?
Make sure you add the L flag to the rule and make sure you place the rules BEFORE the wordpress rules:
RewriteCond %{HTTP_HOST} ^astro\.aspiracoesquimicas\.net$ [NC]
RewriteCond %{REQUEST_URI} !^/astro/
RewriteRule (.*) /astro/$1 [L]
RewriteEngine On .
RewriteCond %{HTTP_HOST} !^astro\.aspiracoesquimicas\.net/
ReWriteRule ^(.*)$ https://aspiracoesquimicas.net/astro/$1 [R=301,L]
use this method

RewriteRule in htaccess change url without content

I have one site with wordpress that have blog page.
So now for this page Url is somthing like http://abc.com/blog.
But i want to convert this url to http://blog.abc.com
I added code in .htaccess file but rewrite is not working. Rewrite mode is also on in apache.
Any one have idea how t o change this url ?
I want to test in my local wamp first, so please give suggestion with localhost too, if possible.
Code is that i tried
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc\.com/blog [NC]
RewriteRule http://blog.abc [R=301,L]
Your rule needs to look something like:
RewriteCond %{HTTP_HOST} ^abc\.com$ [NC]
RewriteRule ^blog/(.*)$ http://blog.abc.com/$1 [R=301,L]
the %{HTTP_HOST} variable is only the hostname, and no path information is part of it (e.g. /blog). The RewriteRule takes at least 2 parameters:
RewriteRule <pattern to match against the URI> <if matched, rewrite/redirect to this URL> <flags>

Resources