Redirect Base + Short Url - .htaccess

I am trying to do a simple custom url shortner .
I have this domain "a.st" that I need to redirect to: "astrit.co"
How can I create a redirect "a.st/234" >> "astrit.co/?p=234"
RewriteEngine on
RewriteCond %{HTTP_HOST} a\.st [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ https://astrit.co/ [L,R=301]

You can use this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^a\.st$ [NC]
RewriteRule ^(234) http://astrit.co/?p=$1 [L,R]

Related

htaccess - redirect old domain to new with exception

htaccess - redirect old domain to new with exception
I have an old domain: www.olddomain.com, with URL files: 1.php,2.php and 3.php
I want to redirect www.olddomain.com to www.newdomain.com, but with the exception that 3.php should be automatically redirected/renamed to 4.php after the redirection, i.e.:
www.olddomain.com/3.php => www.newdomain.com/4.php
The rest should be the same:
www.olddomain.com/1.php => www.newdomain.com/1.php
www.olddomain.com/2.php => www.newdomain.com/2.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
Redirect /3.php /4.php[N]
RewriteRule (.*)$ https://www.newdomain.com/$1 [R=301,L]
Of course it doesn't work the way I want it, please help.
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^\/3\.php [NC] #usually use NC if using Windows
RewriteRule ^ https://www.newdomain.com/4.php [R=301,L]
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !\/3\.php [NC] #usually use NC if using Windows
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]
#or if it adds two slashes use https://www.newdomain.com$1
Have specific redirect before generic redirect rule:
RewriteEngine on
# redirect 3.php
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteRule ^3\.php$ https://www.newdomain.com/4.php [L,NC,R=301]
# redirect everything else
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteRule ^ https://www.newdomain.com%{REQUEST_URI} [R=301,L,NE]

Htaccess redirect from subdomain, but not it's folders

I have
sub.domain.com and want it to be redirected to domain.com
But there must not be redirects from e.g. sub.domain.com/folder/ or sub.domain.com/folder/index.html
Everything i've tried does not work...
For example
RewriteEngine on
RewriteCond %{HTTP_HOST} sub.domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://www.domain.com/ [L,R=301]
You can use this :
RewriteEngine on
RewriteCond %{HTTP_HOST} sub.domain\.com [NC]
RewriteCond %{REQUEST_URI} !^/folder/?$
RewriteCond %{REQUEST_URI} !^/folder/index\.html$
Rewriterule ^(.*)$ http://www.domain.com/ [L,R=301]

htaccess redirect subdomain AND subdirectory to external url

I want redirect:
http://cbpq.luisgustavoventura.com/
AND
http://luisgustavoventura.com/cbpq/
to:
http://cbpq.org.br/
i tried:
RewriteCond %{HTTP_HOST} ^(cbpq\.luisgustavoventura\.com|luisgustavoventura\.com/cbpq)$ [NC]
RewriteRule ^(.*) https://www.cbpq.org.br/$1 [L,R]
but doesn't work.
Please, suggest.
You cannot match /cbpq using %{HTTP_HOST} variable. It is better to keep these as 2 separate rules:
RewriteCond %{HTTP_HOST} ^luisgustavoventura\.com$ [NC]
RewriteRule ^cbpq(/.*)?$ http://www.cbpq.org.br$1 [L,NC,R=302]
RewriteCond %{HTTP_HOST} ^cbpq\.luisgustavoventura\.com$ [NC]
RewriteRule ^(.*)$ http://www.cbpq.org.br/$1 [L,NC,R=302]

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]

Redirect variable page to variable subdomain wildcard

I am stuck on the follow htaccess situation.
I want to redirect pages to subdomains.
Url example right now;
http://domain.tld/user/foo
I need to redirect this to;
http://foo.domain.tld
The subdomain is genereated by wildcard.
I tried the follow without succes;
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.tld [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.tld?$
RewriteRule (.*) s/index.php?user=%1 [NC,QSA]
RewriteRule ^user/(.*) (.*) [R=301,L]
Regards,
Nick
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.tld [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.tld?$
RewriteRule (.*) s/index.php?user=%1 [NC,QSA]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.tld [NC]
RewriteRule ^user/([a-zA-Z0-9-.]+) http://$1.domain.tld/ [R=301,L]

Resources