So, I can't quite figure out the redirect for this. I'm moving a subdomain and all of its content to another domain, but want to add a variable to the end of every url so that it ends up like so:
http://old.domain.com/products/something-or-other.html
turns into
http://www.newdomain.com/products/some-or-other.html?p=abc
I tried this but it doesn't add the variable unless you're only on the root of the domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.domain.com$
RewriteRule (.*)$ http://new.domain.com/$1/p_ig=abc [R=301,L]
EDIT (figured it out with a RedirectMatch instead):
RedirectMatch 301 ^/(.*)/(.*)$ http://new.domain.com/$1/$2?p_ig=abc
You can try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old\.domain\.com$ [NC]
RewriteRule ^ http://new.domain.com${REQUEST_URI}?p_ig=abc [R=302,L,QSA]
Once you verify that it's working fine then change R=302 to R=301.
Related
I try to redirect a ddos attacks. I use redirectmatch conditions, but somehow it is not working in my htacces. the code is
RedirectMatch 301 \d*\?_uw=\d* http://www.someurl.com
or
RewriteRule ^\d*\?_uw=\d* http://www.someurl.com [L,R=301]
None of above is working. I would like to match following urls where numbers are always changing 197831051715412?_uw=9351823359
You can use:
RewriteEngine on
RewriteCond %{QUERY_STRING} _uw=\d*
RewriteRule ^\d*$ http://www.someurl.com/? [L,R=301]
With this other last line:
RewriteRule ^ http://www.someurl.com/? [L,R=301]
You don't test file name (if they also use letters) only _uw=
What I trying to achieve is redirect my domain with www and without it to a subfolder in my application.
Example:
I have www.mysite.in.I want to redirect the user to www.mysite.in/feature/index.php when he hits either www.mysite.in or only mysite.in,but I am not able to achive it.I either end up in a loop or the redirect does not work.
This is what I have tried
RewriteCond %{HTTP_HOST} ^mysite.in
RewriteRule ^(.*)$ http://www.mysite.in/feature/index.php$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.mysite\.in [NC]
RewriteRule ^(.*)$ http://www.mysite.in/feature/index.php$1 [R=301,L]
The above ends in loop.
Redirect 301 mysite.in http://www.mysite.in/feature/index.php
Redirect 301 http://www.mysite.in http://www.mysite.in/feature/index.php
In the above case first redirect works,second fails.
How can I resolve the issue.?
You don't need 2 rules, as they redirect both to the same URL.
There is a loop because you don't test the folder you're in. The RewriteCond on HTTP_HOST is useless because you always be on mysite.in or www.mysite.in (if not leave it).
Try this :
RewriteCond %{REQUEST_URI} !^/feature/ [NC]
RewriteRule ^(.*)$ http://www.mysite.in/feature/index.php$1 [R=301,L]
I am trying to redirect the following (respectively):
http://sub.firstdomain.com/d/(all_files_and_folders)
http://sub.firstdomain.com/d2/(all_files_and_folders)
to
http://sub.seconddomain.com/d/(all_files_and_folders)
http://sub.seconddomain.com/d2/(all_files_and_folders)
There are other files and folders under the first subdomain that I do not want redirected. Previously this was working but now it seems like Go Daddy changed something and what I had is no longer working. Here it is:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.+) /dstats/count.php?statspage=$1 [L,NC,QSA]
RewriteRule ^(.+)\.deb$ /dstats/count.php?file=$1.deb [L,NC,QSA]
RewriteCond %{HTTP_HOST} ^sub\.
RewriteRule ^(d2?)/(.*)$ http://sub.seconddomain.com/$1/$2 [L,R=301]
You can ignore the RewriteRule. It is working fine. I wanted to make sure I included the entire .htaccess file just in case. My issue is with RewriteCond it seems.
The following should work:
RewriteEngine On
Redirect 301 /d/ http://sub.seconddomain.com/d/
Redirect 301 /d2/ http://sub.seconddomain.com/d2/
The above should only redirect anything in the /d/ and /d2/ folder of the sub subdomain.
EDIT: Second try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1\.
RewriteRule ^(d2?)/(.*)$ http://sub2.mydomain.com/$1/$2 [L,R=301]
Read a ton on creating the proper redirects, but still having an issue.
Moving a site from one domain unto another. The directory structure has changed as well. The subpages are working great, but the home page isn't. Here the code that I'm using:
RewriteEngine on
//301 Redirect Old File
RewriteRule oldsite.net newsite.com [R=301,L]
RewriteRule ^p_gallery.* http://www.newsite.com/gallery [R=301,L]
RewriteRule ^p_purchase.* http://www.shop.newsite.com [R=301,L]
Thanks!
Make sure you have enabled mod_rewrite.
Because your first rule is wrong:
RewriteRule oldsite.net newsite.com [R=301,L]
You can only match REQUEST_URI in the RewriteRule.
It should be like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.net$ [NC]
RewriteRule ^ http://newsite.com%{REQUEST_URI} [R=301,L]
I have written a simple redirect condition as:
RewriteCond %{HTTP_HOST} !^my-domain\.com$
RewriteRule ^(.*)$ http://my-domain.com/hu/$1 [L,R=301]
It redirects correctly from www.mysite.com to mysite.com/hu/
But it does not redirect mysite.com to mysite.com/hu/
Please help
You've cleary copied this code without understanding it. This is a typical htaccess to remove the www. part of a domain.
To redirect your homepage to a subfolder, use this code instead :
RewriteCond %{HTTP_HOST} ^(www\.)?my-domain\.com$
RewriteCond %{REQUEST_URI} !^hu/$
RewriteRule ^(.*)$ http://my-domain.com/hu/$1 [L,R=301]