I want to use mod_rewrite on my sub domain:
ads.domain.org/details.php
I need to rewrite it to:
ads.domain.org/something.html
I can do this in main domain:
RewriteEngine On
RewriteRule ^something\.html$ /details.php?id=1 [L]
But I cant do it on sub domain.
Usually the subdomain maps to a different host directory, thus you also need to add the .htaccess to that directory for it to work, also you may need to activate mod_rewrite on that directory maybe even on your virtual host level, just some pointers...
Add a RewriteCond to check HOST value:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ads\.domain\.org$ [NC]
RewriteRule ^something\.html$ /details.php?id=1 [L,QSA,NC]
Related
We have a WordPress site/single app which serves two domain names: example.com and example.es.
In our .htaccess file we have currently have the following rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.es
RewriteRule ^(.*)$ http://www.exmaple.es/$1 [R=permanent,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
We also need to redirect everything from example.com/es/... to example.es/.... I have tried multiple examples that I could find, but none of them worked (ended up in 500 server error and empty log), here are a few of them:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/es/(.*)$
RewriteRule ^(.*) http://www.example.es/%1 [R=302,NC]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com/es [NC]
RewriteRule ^(.*)$ http://www.example.es/$1 [R=301,NC,L]
All of the new rules were placed inside the <IfModule mod_rewrite.c>
Any help or guidance is much appreciated.
#Domas Hi Domas, the process in your case is to update you site installing some important extension about the domain change.
Changing the preferred domain name alias WordPress uses
If your WordPress site has a domain name alias pointing to it, and you want WordPress to prefer the alias domain name in links that it generates, you can update the domain name in the WordPress dashboard:
Click Settings.
Change the WordPress Address (URL) to the new URL that you want to use.
Change the Site Address (URL) to the same value.
Click Save Changes.
You need WP Super Cache, this extension help you to update automatically the .htaccess and change all the needs as you did on you configuration site.
First install the extension https://support.tigertech.net/move-wordpress#updating-htaccess-wp-jmp
Also if you don't need any extension and you want to do by the hand just redirect like this example as needs :
#the simple redirection
Redirect 301 /es http://www.example.es/
#Redirect from old domain with subdirectory to new domain
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/es/(.*)$
RewriteRule ^(.*) http://www.example.es%{REQUEST_URI} [R=302,NC]
It depend of you needs i prefer the last one. Regards
I have the following .htaccess code that successfully rewrites subdomain directories. So if a user visits jim.domain.com they get served placeholder.php?page_type=profile. However, this also affects the main directory http://domain.com. I'd like it so that anything with a subdomain is directed to the placeholder.php page, but using the main directory with no subdomain would act as usual, going to the index.php in the main directory. How would I achieve this? Thanks for any advice.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^exclude.domain.(.*)
RewriteCond %{HTTP_HOST} !^www.domain.(.*)
RewriteCond %{HTTP_HOST} (.*)\.domain\.com
RewriteRule ^$ placeholder.php?page_type=profile [L,QSA]
If your wanting all requests for test.domain.com to go to domain.com/placeholder.php?page_type=profile as in your comment then you need to include the domain in the rewrite
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^exclude.domain.(.*)
RewriteCond %{HTTP_HOST} !^www.domain.(.*)
RewriteCond %{HTTP_HOST} (.*)\.domain\.com
RewriteRule ^$ http://domain.com/placeholder.php?page_type=profile [L,QSA]
this will not how ever deal with this part
but using the main directory with no subdomain would act as usual, going to the index.php in the main directory
because you have no file/directory miss rules that redirect to index.php. Do you need those, or really just want to solve the first part?
I also wonder if your wanting profile replaced with the subdomain match, in which case you want
RewriteRule ^$ http://domain.com/placeholder.php?page_type=%1[L,QSA]
but both of these examples will not rewrite any path of test.domain.com/longer_url because the ^$ is only matching an empty URL path. But how you want to handling paths needs to be decided before a suitable Reerite can be proposed.
I have a multi-subdomain multi-lingual website setup and I need to redirect a language subfolder of a certain domain. eg. au.domain.com/us/request_uri to au.domain.com/en/request_uri. This rule needs to be ignored on other domains. All domains are run off the same codebase and all use the one htaccess file (drupal install with domain access module). This shouldn't affect how the htaccess rule is set though.
Here is one way to do it:
RewriteEngine On
RewriteRule ^us/(.*)$ http://au.domain.com/en/$1 [L,R=301]
Redirects:
http://au.domain.com/us/anything to
http://au.domain.com/en/anything/
UPDATED
RewriteEngine On
RewriteRule http://au.domain.com/us/^(.*)$ http://au.domain.com/en/$1 [L,R=301]
Only http://au.domain.com/us/anything will be redirected to
http://au.domain.com/en/anything/
OR
RewriteEngine On
RewriteCond %{HTTP_HOST} ^au.domain\.com$ [NC]
RewriteRule ^us/(.*)$ http://au.domain.com/en/$1 [L,R=301]
Hope this helps.
I'm relatively new to using .htaccess, and have never done any coding besides what I've read online. I'm using Bluehost, and I'd like to redirect my blog subdirectory to a subdomain. Example: I'd like to redirect www.example.com/blog to blog.example.com.
I already have code in place to always add www. to the beginning of my blog address in the root folder, but I don't know how to accomplish the above redirect by using code in .htaccess. Any help would be appreciated!
A lot of web hosts today provide an easy implemention for subdomain creation in their administration panels. You just need to to go there, choose you subdomain name, and then point it to a directory in your tree.
If you can't, then it will be a little more complicated (You will need to resolve that subdomain to your server ip, configure some virtual hosts ... etc) and you may not have enough privileges to do that (unless you are on a dedicated server).
Edit 2
To redirect requests to www.example.com/blog to blog.example.com, try this :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^blog/(.*)$ http://blog.example.com/$1 [L,QSA,R=301]
RewriteCond %{HTTP_HOST} ^blog\.example\.com$
RewriteCond %{REQUEST_URI} !^blog/
RewriteRule ^(.*)$ /blog/$1 [L,QSA]
I wanted to add my two cents,
1) to answer the question above, this rewrite should fix it:
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^/blog$ http://blog.example.com [R=302,L]
2) but, I think this is not enough by itself, you also need to change DNS, so that blog.example.com is pointed at the right server, and this can be done by a cname similar to this:
blog.example.com CNAME example.com TTL 1080
(not exactly how it will look, but use your DNS webinterface to set this up).
Have you tried this one?
RewriteEngine on
RewriteBase /
RewriteRule ^/blog/(.*)$ http://blog.subdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^check.domain.info$
RewriteCond %{REQUEST_URI} !^/check/
RewriteRule (.*) /check/$1
To redirect subdomain1 and subdomain2 and directory3 to a directory with HTTPS://, I use the following code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain1.example.com [OR]
RewriteCond %{HTTP_HOST} ^subdomain2.example.com [OR]
RewriteCond %{HTTP_HOST} ^example\.com/subdomain3 [NC]
RewriteRule ^(.*)$ https://example.com/subdirectory/$1 [R=301,L]
I'd like to redirect a website from http:// domain.com & http:// www.domain.com to http://v2.domain.com, while maintaining access to http:// (www.)domain.com/images/*
I've tried several methods but somehow I can no longer access the /images folder anymore.
P.S: both subdomain & root has different content/CMS. Any ideas as to how to implement this?
Thanks
You haven't explained exactly how these are configured. I'm going to assume that www.domain.com and v2.domain.com are different virtual hosts:
You should be able to do this in your .htaccess file or apache configuration for www.domain.com:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !images/
RewriteRule ^/(.*) http://v2.domain.com/$1 [L,R]
I realised something like this could work as well. Probably need some testing, but if this is wrong do comment.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{HTTP_HOST} !v2\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://v2.domain.com/ [R=302,L]