htaccess 301 redirctions of a single file - .htaccess

I have this .htaccess code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^articles/([^/\.]+)/?$ articles.php?url=$1
RewriteRule ^([^/\.]+)/?$ articles.php?t=$1
Redirect 301 /html/index.php http://www.mysite.com/html
Redirect 301 /‪html/html_syntax.php http://www.mysite.com/articles/html-syntax
Redirect 301 /html/favicon.php‬ http://www.mysite.com/articles/how-to-create-favicon
Redirect 301 /articles/html-anchore‬ http://www.mysite.com/articles/html-anchor
But for some reason, none of the 301 Redirections works, any suggestions?
I have tried using:
RedirectMatch 301 ^/oldpage\.php$‬ http://www.mysite.com/newpage.php
But that didnt work either.

After the agent from Godaddy was not able to solve my issue, I decided to go to my GoDaddy account and use the Redirect tool they have there. After creating some redirects using the tool I opned my .htaccess file to look for what changes were made. GoDaddy is using the rewriterule to creat redirects.
Here is what I saw:
rewriterule ^folder\/oldFile\.html "http\:\/\/mysite\.com\/folder\/newFile\.html" [R=301,L] #4f47f0ade2879
the number at the end is probably used by the GoDaddy tool as a unique key for that redirect.
everything works now!

Related

Redirect 301 with condtion

I can redirect all traffic to new blog subdirectory like:
Redirect 301 / https://new-website.com/blog/
However, I want this redirect to happen ONLY if it comes from old website subdomain referral:
https://blog.old-website.com
Any idea?
You can use mod-rewrite
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^https://blog\.oldsite\.com
RewriteRule ^.*$ http://newsite.com/blog%{REQUEST_URI} [L,R]

Redirect 301 .htaccess Redirect Error

I have re-vamped a website and I'm attempting to ensure all of the old, deleted directories are redirected to the new pages. For example, I have a directory called /category/ and want it redirected to http://website.com/interiordesign.html. The root website is still the exact same. I've implemented some coding in the .htaccess file, but it is giving me a redirect error.
Here is my code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]
Redirect 301 /category/ http://website.com/interiordesign.html
Redirect 301 /interior-design-portfolio/ http://website.com/interiordesign.html
Redirect 301 /contact-location/ http://website.com/contact.html
Redirect 301 /tag/ http://website.com/blog.html
I have the remove / rule in place, as I found when I didn't implement that, it was taking the user to interiordesign.html/ and with the slash, it didn't work.
Apologies for my poor coding, this is not my area of expertise.

htaccess 301 redirect domain but not a specific folder and files

I tried searching in first here in stackoverflow and google for the best answer but I could not find a solution to my problem.
My question is can I add a condition where a specific sets of folder/files in my server will not be affected by a htaccess 301 redirection from old domain to new domain?
this is the htaccess I added.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !mysite.com.au$ [NC]
RewriteRule ^(.*)$ http://mysite.com.au/$1 [L,R=301]
the old domain was mysite.com without the .au and the above code will direct all links in my old site to be transfer to .com.au , but I want some of my folder in .com to be not affected by the htaccess 301 redirection, for example.
mysite.com/folder1/,
mysite.com/images/,
mysite.com/js/
and some files will not be affected by this redirection. Can any one point me to on how to fix or add a rule so a specific folder will not be affected by the old domain to new domain htaccess 301 redirection I added?
thanks,
You can add a RewriteCond in your redirect rule for exceptions:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(folder/|images/|js/) [NC]
RewriteCond %{HTTP_HOST} !^mysite\.com\.au$ [NC]
RewriteRule ^ http://mysite.com.au%{REQUEST_URI} [NE,L,R=301]

How to fix a htaccess 301 redirect that contains a ? symbol

A new website has just gone live and there is a htaccess file which has 301 redirects in order to direct people from the old pages on the old domain to the new pages on the new domain.
However, because there is a ? and = symbol in the links it's not working.
I understand I'll need to take advantage of the query string, but I can't work out how to get these three examples working.
Redirect 301 /index.cfm?task=what_we_do http://domain.com/services/
Redirect 301 /pagecontent/_newsitem.cfm?newsid=63 http://domain.com/name-of-article/
Redirect 301 /pagecontent/_people.cfm?peopleid=3 http://domain.com/about-us/meet-the-team/john-smith/
Can anyone help?
You can't use a query string in the redirect. you have to use mod_rewrite.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^task=what_we_do$
RewriteRule ^index.cfm http://domain.com/services/? [R=301,L]
RewriteCond %{QUERY_STRING} ^_newsid=63$
RewriteRule ^pagecontent/_newsitem.cfm http://domain.com/name-of-article/? [R=301,L]
RewriteCond %{QUERY_STRING} ^_peopleid=3$
RewriteRule ^pagecontent/_people.cfm http://domain.com/about-us/meet-the-team/john-smith/? [R=301,L]

Redirect subdomain of one domain to a subdomain of another domain

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]

Resources