redirecting from short url - .htaccess

Let's say short.com is the short domain and long.com is the long domain
updated:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.long.com
RewriteRule (.*) http://long.com/ [R=301]
RewriteCond %{HTTP_HOST} ^short\.li$ [NC]
RewriteCond %{REQUEST_URI} !^/redirect
RewriteRule ^(.*)$ /redirect?short=$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)short\.li$
RewriteRule ^$ http://long.com/ [L,R=301]
both domains point to that root directory. When I type short.li I end up on long.com/?l=
how did I manage to screw up like that?^^

Try this in your htaccess file :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)short\.com$
RewriteRule ^$ http://www.long.com/ [L,QSA,R=301]
Remove RewriteEngine on if it is already there

I think you might want something along the lines of this:
RewriteEngine on
RewriteCond {REQUEST_URI} !/
RewriteCond {HTTP_HOST} short.com
RewriteRule ^(.*) http://long.com/redirect.php?short=$1 [L,R=301]
RewriteCond {REQUEST_URI} /
RewriteCond {HTTP_HOST} short.com
RewriteRule ^(.*) http://long.com/ [L,R=301]
Not sure if the regex is needed on that last one or not, but something like this should work

Related

htaccess language rediretion

I have a website, www.thesite.com and an alias www.lesite.com
i need a htaccess redirection:
I would like that, when I go to www.thesite.com/fr, it redirects me to www.lesite.com/fr
Likewise, when I go to www.lesite.com/en, I would like it to redirect me to www.thesite.com/en
I have tried different methods but i only succeed to create infinite loops !----
Options +FollowSymlinks
RewriteRule ^fr$ http://dev.mariage.ch/fr/ [L]
RewriteRule ^de$ http://dev.hortzeit.ch/de/ [L]
OR
RewriteCond %{HTTP_HOST} !^dev\.hortzeit\.ch\/de\/
RewriteRule (.*) http://dev.hortzeit.ch/de$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^dev\.mariage\.ch\/fr\/
RewriteRule (.*) http://dev.mariage.ch/fr$1 [R=301,L]
You can't use path as part of RewriteCond for HTTP_HOST
instead of dev.hortzeit.ch/de you must use just host part dev.hortzeit.ch
RewriteEngine On
RewriteCond %{HTTP_HOST} !^dev\.hortzeit\.ch [NC]
RewriteRule ^de(/?.*)$ http://dev.hortzeit.ch/de$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} !^dev\.mariage\.ch [NC]
RewriteRule ^fr(/?.*)$ http://dev.mariage.ch/fr$1 [R=301,NC,L]

htaccess rewrite - pulling variable from dynamic host

I have a set of mod-rewrite rules which look like this:
RewriteCond %{HTTP_HOST} AAAexample.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.AAAexample.com/folder/AAA [R=301,L]
RewriteCond %{HTTP_HOST} BB-BBexample.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.BB-BBexample.com/folder/BB-BB [R=301,L]
RewriteCond %{HTTP_HOST} CCCCCexample.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.CCCCCexample.com/folder/CCCCC [R=301,L]
Essentially I have a set of domains matching (PATTERN)example.com, where (PATTERN) can contain any combination of letters and hyphens.
Is there a way to condense the above rules into a single set such that I Pull PATTERN as a dynamic variable into the final rewrite URL?
Thanks!
You can use:
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)(example\.com)$ [NC]
RewriteRule ^/?$ http://www.%1%2/folder/%1 [R=301,L]

htaccess rewrite rule for subdomains with page id

i want to redirect
http://subdomain.example.com/index.php?pageID=45
to
http://example.com/subdomain/45.html
Please help me with this
i tried
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.example.com/sudomain/$1 [L,R=301]
You can replace your code by this one in your htaccess (in root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteCond %{QUERY_STRING} ^pageID=([1-9][0-9]*)$ [NC]
RewriteRule ^index\.php$ http://example.com/subdomain/%1.html? [R=301,L]

htaccess redirect only for one domain

I have several domains pointing to the same webspace (www.domain1.com, www.domain2.com, www.domain3.com, etc.). Only when one domain is used, e.g. www.domain1.com, I want to redirect users from different short link, e.g. www.domain1.com/link or www.domain1.com/link2, to another URL.
I have put together the following. The RewriteCond is probably ok but the RewriteRules doesn't work:
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteRule ^/test$ http://www.domain1.com/xyz.php [R=301]
RewriteRule ^/test2$ http://www.domain1.com/abc.php [R=301]
RewriteRule ^/test3$ http://www.domain1.com/abc/test10.php [L,R=301]
Do you have any tip how the correct RewriteRules should look like?
Hopefully this helps you get going in the right direction...
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteCond %{REQUEST_URI} ^(/test/)$ [NC]
RewriteRule ^(.*)$ http://www.domain1.com/xyz.php [R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteCond %{REQUEST_URI} ^(/test2/)$ [NC]
RewriteRule ^(.*)$ http://www.domain1.com/abc.php [R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC]
RewriteCond %{REQUEST_URI} ^(/test3/)$ [NC]
RewriteRule ^(.*)$ http://www.domain1.com/abc/test10.php [L,R=301]

disabled htaccess for selected directory

i have a htaccess code shown below:
RewriteEngine On
RewriteCond $1 !^/administrator
RewriteCond %{HTTP_HOST} ^localhost/host
RewriteRule (.*) http://localhost/host/$1 [R=301,L]
RewriteRule ^([-\w]+)?/?([-\w]+)?/?([-\w]+)?/?$ index.php?seg1=$1&seg2=$2&seg3=$3
but it still read the htaccess in administrator folder. is the code incorrect?
Thanks.
RewriteCond statements apply to one RewriteRule only.
You need to repeat your RewriteConds for the second rewrite rule (and use REQUEST_URI):
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/administrator
RewriteCond %{HTTP_HOST} ^localhost/host
RewriteRule (.*) http://localhost/host/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/administrator
RewriteCond %{HTTP_HOST} ^localhost/host
RewriteRule ^([-\w]+)?/?([-\w]+)?/?([-\w]+)?/?$ index.php?seg1=$1&seg2=$2&seg3=$3

Resources