I have installed wildcards successfully. And I managed to make dynamic subdomain to work with a simple trick.
.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# *.example.com
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?subdomain\.php$
RewriteRule .? subdomain.php?subdomain=%1&path=%{REQUEST_URI} [L,QSA]
Currently in something.example.com is shown the output of subdomain.php, great.
But I want to have it working as I can enter at
pre102.example.com/folder/anotherfolder/script.php?param=1
and show the output of
example.com/folder/anotherfolder/script.php?param=1&pre=102
RewriteCond %{QUERY_STRING} !pre=[0-9]
RewriteCond %{HTTP_HOST} ^pre([0-9]+)\.example\.com$ [NC]
RewriteRule ^(.*)$ /$1?pre=%1 [L,QSA]
Related
In the root the code already working (for example):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.co.uk [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.co.uk [NC]
RewriteRule ^(.*)$ https://www.NEW111NEW.com/$1 [L,R=301,NC]
Now I need to redirect a subdomain (like):
from:
https://info.oldsite.co.uk/blog/some-blog-post-a
to:
https://info.NEW111NEW.com/blog/some-blog-post-a
I tried - 1 (not working):
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^info.oldsite.co.uk [NC]
RewriteRule ^blog/(.*) http://info.NEW111NEW.com/blog/$1 [L,R=301,NC]
Also tried - 2 (not working):
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(info\.)?oldsite\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://info.NEW111NEW.com/blog/$1 [R=302,L]
---Update---
When tried - 3 (its working partly):
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^info\.oldsite\.co\.uk [NC]
RewriteRule ^(.*)$ https://info.new.com/blog/$1 [L,R=301,NC]
Here
https://info.oldsite.co.uk/dsadasdsad
is going to
https://info.new.com.co.uk/%60https://info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/%60https:/info.new.com.com/blog/blog/fsdfdsfsd%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60%60
AND
https://info.oldsite.co.uk/blog/dsadasdsad
is going to
https://info.new.com.com//blog/dsadasdsad (almost working but a double slash "//" here)
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^info\.oldsite\.co\.uk [NC]
RewriteRule ^(.*)$ https://info.new.com%1/$1 [L,R=301,NC]
So, the info.oldsite.co.uk/blog/xyzxyz is going to info.new.com/blog/xyzxyz
I am trying to achieve any one of the following:
http://ca.domain.com/Category/SubCategory -> http://www.domain.com/index.php?country=ca&category=Category&subcategory=Subcategory
http://www.domain.com/ca/Category/SubCategory -> http://www.domain.com/index.php?country=ca&category=Category&subcategory=Subcategory
I have browsed around but unfortunately haven't been able to figure out any working solution. For the first kind I tried the following code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteRule ^(.*)/$ http://www.domain.com/index.php&country=%1&category=$1 [L]
The issue with sub domain is that it doesn't redirect anywhere at all. I read around and it says I need to setup wildcard virtual host. I haven't been able to figure out how to do that on godaddy. So not sure how to do it.
As for the second kind, I used the following code:
RewriteEngine on
RewriteRule ^(.*)/?(.*)/ home.php?country=$1&category=$2 [B]
But that didn't work for me either. Any help in this regard would be highly appreciated. Thank you
As for Category & Subcategory, Subcategory is kind of mandatory. So it should also work for following link:
http://www.domain.com/ca/Toronto/Programming -> http://www.domain.com/index.php?country=ca&location=Toronto&subcategory=Programming
http://www.domain.com/ca/Programming -> http://www.domain.com/index.php?country=ca&location=&subcategory=Programming
I am not quite sure as to how to tell .htaccess if it is $1=subcategory or $2=subcategory since they switch in scenario 1 & 2.
Thanks to immense help from #anubhava I have reached to the following:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ adlisting.php?country=%1&category=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ adlisting.php?country=%1&location=$1&category=$2 [L,QSA]
RewriteCond %{HTTP_HOST} ^(www\.)?\.domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/?$ adlisting.php?country=$1&category=$2 [L,QSA,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?\.domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ adlisting.php?country=$1&category=$2&subcategory=$3 [L,QSA,NC]
Have these rules in root .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/?$ index.php?country=%1&category=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?country=%1&category=$1&subcategory=$2 [L,QSA]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/?$ index.php?country=$1&category=$2 [L,QSA,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^([a-z]{2})/([^/]+)/([^/]+)/?$ index.php?country=$1&category=$2&subcategory=$3 [L,QSA,NC]
Per: https://exp-resso.com/blog/post/2011/08/securing-your-expressionengine-website-with-https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond $1 ^(member|account|checkout|system) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This tells your server “If HTTPS is off, and the request starts with
member OR account OR checkout OR system (not case sensitive), redirect
to https://current-domain/current-page”. It’s a nice simple method of
locking down entire subfolders / template groups.
I've added this to my htaccess file like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond $1 ^(sign-in|sign-up) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
However, when I go to my http://mydomain.com/sign-in, the URL doesn't change to https://mydomain.com/sign-in. Any idea what's wrong?
EDIT 1:
My htaccess also has the following (to remove "www") and I wonder if having both might be causing the problem?
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
EDIT 2:
Process of elimination, it turns out this is causing the problem:
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
When I comment out the RewriteRule, the https:// is forces. What's causing the conflict?
Try to put (sign-in|sign-up) condition inside RewriteRule:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(sign-in|sign-up)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R=301]
What about this? (If port == 80 then redirect )
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} member [OR]
RewriteCond %{REQUEST_URI} account [OR]
RewriteCond %{REQUEST_URI} checkout [OR]
RewriteCond %{REQUEST_URI} system
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
First make sure that rewrite works on your server and that the htaccess is read (e.g. by issuing a redirect on every URL).
Then use RewriteCond %{REQUEST_URI} ^/(sign-in|sign-up) instead of RewriteCond $1 ^(sign-in|sign-up) [NC]
It works and is easier to read too
So you htaccess should look like this
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^/(sign-in|sign-up) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I need it so when i go to mydomainname.com/page/week1 it will show mydomainname.com/page.php?month=week1. Will my code do that ?
rewriteengine on
rewritecond %{HTTP_HOST} ^www.mydomianname.com$ [OR]
rewritecond %{HTTP_HOST} ^mydomianname.com$
rewriterule ^mydomianname\.com/page/?([-A-Za-z0-9]+)/?$ "http\:\/\/mydomianname\.com\/page\.php?month=$1" [L]
When I go to mydomainame.com/page/week1 I get
the requested URL /page/week1 was not found on this server.
my current http access
rewriteengine on
rewritecond %{HTTP_HOST} ^www.fetustobaby.com$ [OR]
rewritecond %{HTTP_HOST} ^fetustobaby.com$
rewriterule ^fetustobaby\.com\/page\/([-A-Za-z0-9]*)\/?$ page.php?month=$1 [L]
Your code has some issues like RewriteRule only matches URL and host name matching is not part of RewriteRule. Here is the fixed code that you can use in your .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mydomianname\.com$ [NC]
RewriteRule ^page/([^/]+)/?$ /page.php?month=$1 [L,NC,QSA]
In .htaccess I see how to rewrite /index.html to point to the main domain:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*\/index\.html?\ HTTP/
RewriteRule ^(.*)index\.html?$ "/$1" [R=301,L]
I also understand how .htaccess can prevent the site from being indexed under WWW and without it
RewriteEngine on
rewritecond %{http_host} ^mycustomcloset.com [nc]
rewriterule ^(.*)$ http://www.mycustomcloset.com/$1 [r=301,nc]
But how do you do both at the same time?
In other words, I'd like mycustomcloset.com and mycustomcloset.com/index.html both to point to http://www.mycustomcloset.com.
I did not understand the first code on your question, however you can still try this one:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R,NE]
Now, if you also want to redirect mycustomcloset.com/index.html and www.mycustomcloset.com/index.html into www.mycustomcloset.com then you can try this:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R,NE]
RewriteRule ^index.html$ http://www.mycustomcloset.com [R,NE]