How to mod-rewrite subdomain directory using htaccess - .htaccess

I have something like this.
http://www.mydomain.com/page.php?s=database&name=page
How do i mod rewrite it in such a way that it become.
http://www.database.mydomain.com/page/
I successfully map it into a subdomain format as below using (database.mydomain.com)
RewriteCond %{HTTP_HOST} ([^.]+)\.localhost
RewriteRule ^(.*)$ s/index.php?s=%1
Have no idea how to proceed further. This is what i have :
RewriteCond %{HTTP_HOST} ([^.]+)\.localhost\([^.]+)\
RewriteRule ^(.*)$ s/page.php?name=%1&s=%2
Appreciate any expert help. :)

You don't need to rewrite subdomains
Rewrite only request uri and be fine.

Related

Redirect url with get variables use .htaccess

It is possible to redirect in .htaccess
this url
http://test.com/uploads/image.jpg?w=200
to this
http://test.com/public/uploads/image/200.jpg
?
I need this to cache system in my rest API.
I'm not sure that is possible rewrite get variable in this way.
Cheers
Check this rule, maybe it help.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^uploads/image.jpg
RewriteCond %{QUERY_STRING} w=(.*)
RewriteRule ^(.*)$ /public/uploads/image/%1.jpg? [R=301,L]

How do I redirect a subdomain to an HTML file?

I've been trying out all sorts of examples to redirect subdomains to files on my server.
So, let's say someone went to apple.domain.com.
Using htaccess, I want it to redirect to domain.com/apple.html
Here's the rules I have right now, which don't work.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain.com$ [NC]
RewriteRule ^ /%1.html [L]
Thanks so much in advance for the help.

Htaccess redirect without url rewrite

I have a little problem in hands.
I am setting up a domain that as 3 languages, example.com for principal domain, en.(...) for english and de.(...) for germany.
Usually I only redirect the httpdocs from the subdomains to the main with ln -S because all languages executes the same code, the difference is matched from php and mysql.
My new host don't provide any ssh connection so I have to use a different approach on this.
It was told to me that it can be done by .htaccess but I already tried a lot of things but only can redirect, changing the url and that's not possible, it have to keep the same, the contents yes, will be from another domain. Can someone help?
This code should looks like the one you're searching for :
www.domain.en .htaccess
RewriteBase /
RewriteRule ^(.*)$ http://www.domain.com/en/$1 [L,R=301]
www.domain.de .htaccess
RewriteBase /
RewriteRule ^(.*)$ http://www.domain.com/de/$1 [L,R=301]
You'll propably adapt the http://www.domain.com/lang/$1 part to your needs.
EDIT
Following your comment, this is a code for subdomains redirections :
domain.com .htaccess
RewriteCond %{HTTP_HOST} ^en\.domain\.com [NC]
RewriteRule (.*) http://domain.com/en/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^de\.domain\.com [NC]
RewriteRule (.*) http://domain.com/de/$1 [QSA,L]

How to rewrite /?custom_ref= with /?ref= using htaccess rewrite

How to rewrite
/?custom_ref=
with
/?ref=
using htaccess rewrite???
RewriteEngine On
RewriteCond %{QUERY_STRING} custom_ref=(.*)
RewriteRule (.*) /?ref=%1 [R=301,L]
Can you please tell me the directory/file that you using this query on so I make sure this code will only work with it.

modrewrite - rewrite to new domain from subdirectory

Damn you modrewrite
I have a website hosted at a url like:
http://mydomain/mocks/thesite/
Now I want to move it to a new domain
http://thesitesdomain.com/
My htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule (.*) http://www.thesitesdomain.com/$1 [R=301,L]
Now this works fine as long as there is something after /mocks/thesite/. eg: http://mydomain/mocks/thesite/index.html redirects to http://www.thesitesdomain.com/index.php.
However the problem is that:
http://mydomain/mocks/thesite/ redirects to http://thesitesdomain.com/mocks/thesite/. Any idea why? How to stop this?
The .htaccess file is in the root of /mocks/thesite/ (if that helps)
Thank you
You should try to use the variable REQUEST_URI you might have a little more success with that. It should be the request uri and file name. To
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI} [R=301,L]
I can't remember but to also redirect with the query string (get variables) I think you need to add it like this.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]
Been a while since really doing a domain redirect....
BTW this is a good read on htacces configuration:
http://corz.org/serv/tricks/htaccess2.php

Resources