RewriteRule not triggered - apache

I'm trying to change from
http://www.myhost.com/en/team/league-of-legends/3798/destiny
to
http://lol.myhost.com/en/team/league-of-legends/3798/destiny
I tryed different combinaisons for my Apache2 server including the following :
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^/(.*)/team/league-of-legends/(.*)/(.*) http://lol.myhost.com/$1/team/league-of-legends/$2/$3 [R=301,L]
But it seems not to work (i checked in an htaccess tester).
What am I doing wrong please ?

You may try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?myhost\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/([^/]+)/team/league-of-legends/([^/]+)/([^/]+)/? [NC]
RewriteRule . http://lol.myhost.com/%1/team/league-of-legends/%2/%3 [R=301,L,NC]
Redirects permanently
http://www.myhost.com/en/team/league-of-legends/3798/destiny or
http://myhost.com/en/team/league-of-legends/3798/destiny
To:
http://lol.myhost.com/en/team/league-of-legends/3798/destiny
Strings en, 3798 and destiny are assumed to be variable, while team and league-of-legends are assumed to be fixed.
For silent mapping, remove R=301 from [R=301,L,NC]

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory of www.myhost.com domain:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(myhost\.com)$ [NC]
RewriteRule ^[^/]+/team/league-of-legends/ http://lol.%1%{REQUEST_URI} [R=301,L,NC]

See if this works. Let me know if it doesn't.
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^([^\/]*)/team/league-of-legends/(.*)$ http://lol.myhost.com/$1/team/league-of-legends/$2 [R=301,L]

Related

Do redirect and add variable to URL through htaccess

I would like to have htaccess redirect oranges.info to
example.com/about.html?=fruit
This is my htaccess file which unfortunately is only doing the redirect and not adding the variable. Any ideas?
Options +FollowSymLinks
rewriteengine on
rewritecond %{HTTP_HOST} ^www.oranges.info$ [OR]
rewritecond %{HTTP_HOST} ^oranges.info$
rewriterule ^domainfolder\/(.*)$ "http\:\/\/example\.com\/about\.html$1?fruit" [R=301,QSA,L]
Options -Indexes
Your rule syntax isn't correct:
rewritecond %{HTTP_HOST} ^(www\.)?oranges\.info$ [NC]
rewriterule ^ http://example.com/about.html?fruit [R=301,QSA,L]
Make sure to test in a different browser.

Rewrite url using .htaccess file

I want to add https in a specified url
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^magsonwink.winkplatform.com/Shopping/paynow
RewriteRule ^(.*)$ https://magsonwink.winkplatform.com/Shopping/paynow%{REQUEST_URI} [QSA,R=301,L]
but this not worked for me. After googling i can't get a specified answer. if any one know about this please help me
Thanks in advance.
Here is the corrected code:
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{HTTPS}s on(s)|
RewriteCond %{HTTP_HOST} ^magsonwink\.winkplatform\.com$ [NC]
RewriteRule ^Shopping/paynow(?:/.*|)$ http%1://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
Above code will work both with HTTP and HTTPS
No need to use QSA flag since you aren't modifying query string
The %{HTTP_HOST} variable is only the hostname, no URL-path info is in it. So you need to remove it and add it to the pattern in your rule:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^magsonwink.winkplatform.com$ [NC]
RewriteRule ^/?Shopping/paynow(.*)$ https://magsonwink.winkplatform.com/Shopping/paynow$1 [QSA,R=301,L]

Mod Rewrite with multiple parameters

I'm trying to setup a rewrite rule so that any text in place of a subdomain will be parameter one and any text after the first forward slash will be parameter two but I'm struggling with regex and am unsure about rewrite terminology.
For example, if someone requested:
joebloggs.mydomain.com
I would like them to see:
mydomain.com/index.php?site=joebloggs
Also, if someone requested:
joebloggs.mydomain.com/contact
I would like them to see:
mydomain.com/index.php?site=joebloggs&page=contact
By "see" I mean see the page, rather than see the URL - it's a CMS-like project so you can probably see where I'm going with it. Also, I've worked out how to remove www. so that's not an issue :)
EDIT
Current .htaccess is:
RewriteEngine On
# Remove trailing slash
RewriteRule ^(.+)/$ $1 [L]
# Remove www
RewriteCond %{HTTP_HOST} ^www.richardmjenkins.com$ [NC]
RewriteRule ^(.*)$ http://richardmjenkins.com/$1 [R=301,L]
# Rewrite for site/page pair
RewriteCond %{HTTP_HOST} ^(.*)\.richardmjenkins\.com$ [NC]
RewriteCond %{REQUEST_URI} !p.php
RewriteRule ^(.+/)?([^/]*)$ p.php?s=%1&p=$2 [QSA,L,NC]
RewriteCond %{HTTP_HOST} ^(.*)\.richardmjenkins\.com$ [NC]
RewriteCond %{REQUEST_URI} !p.php
RewriteRule ^$ p.php?s=%1 [QSA,L,NC]
1. In your host panel : add a subdomain with name : * for enable all subdomains
2. this is your htaccess code :
RewriteEngine On
Options +Followsymlinks
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$ [NC]
RewriteRule ^$ index.php?site=%1 [QSA,L,NC]
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$ [NC]
RewriteRule ^([^/]+)/?$ index.php?site=%1&page=$1 [QSA,L,NC]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^((?!www)[^.]+)\.(mydomain\.com)$ [NC]
RewriteRule ^$ index.php?site=%1 [L,QSA]
RewriteCond %{HTTP_HOST} ^((?!www)[^.]+)\.(mydomain\.com)$ [NC]
RewriteRule ^(.+)$ index.php?site=%1&page=%2 [L,QSA]

Redirecting from subdomain without changing URL

I want to redirect a subdomain with the .htaccess file without changing the URL. But can't figure it out.
ex. i want to turn
http://foo.domain.com
into
http://www.domain.com/users/foo/dashboard.php
I generated a script to do this, but the URL doesn't stay on http://foo.domain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC]
RewriteRule ^ http://www.domain.com/users/%1/dashboard.php [L]
Thanks for the help!
What you're htaccess it is doing is simply saying "if you find this, do a full redirect to that url"
Do this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC]
RewriteRule ^ dashboard.php?domain=%1 [L, QSA]
And it should work (moving to wherever dashboard is in your directory structure on-server, relatively)
Try this (assuming that all the subdomains point to the root directory) :
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^.*$ users/%1/dashboard.php [L]
Proxy flag [P] will do the trick:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.example\.org$ [NC]
RewriteRule http://example.org/users/%1/dashboard.php [P,NC,QSA]
</IfModule>

need to remove www from 2nd level subdomain generically in Apache (using rewrite)

I have the problem but with many subdomains: E.g..
sub1.domain.com and new.domain.com and xsub.domain.com and many many more like this.
How do I remove the www from in front of any of these with one generic rule.
E.g. if someone types www..domain.com or http://www..domain.com to change it to
http://.domain.com
Thanks
You may use the rewrite module to remove the www. when it precedes a sub-domain. In this way, an address like: www.sub1.domain.com would be redirected to sub1.domain.com:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
</IfModule>
Modified tested solution but for http only.
#Allow domain of the form www.domain.com
RewriteCond %{HTTP_HOST} !^www\.([^\..]*)\.([^\..]*)$ [NC]
#Otherwise any other form must be rewritten to remove www
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
#Substitue the complete domain using group %1 in the parentheses of the above condition
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
This will do the job, and return with http://
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^(.*) http://%1/$1 [R,L]
For https, just add the s, as so:
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^(.*) https://%1/$1 [R,L]
Note that this can be done in httpd.conf as well. Using .htaccess is popular but actually slows down the site, especially if there are nested directories.
You do need:
Options +FollowSymLinks
But you do not need Indexes.