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.
Related
I have some files placed under a particular folder in my old domain:
http://www.olddmain.com/subfolder/example1.html
I want to redirect all files under this folder to a new domain.
Example:
http://www.newdomain.com/subfolder/example1.html
How do I do this without losing Ranking of the pages?
Maybe you need this
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.olddomain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^olddomain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
from "Redirecting to a different domain" in Redirecting a Web Folder Directory to another Directory in htaccess
In the olddomain.com/subfolder/.htaccess file you just need a single mod_alias Redirect directive to redirect all files to newdomain.com/subfolder/<file>:
Redirect 302 /subfolder http://www.newdomain.com/subfolder
Change the 302 (temporary) to 301 (permanent) only when you are sure it's working OK. (301s are cached hard by the browser, so can make testing problematic.)
However, if olddomain.com and newdomain.com point to the same place then you will need to use mod_rewrite and include a condition that specifically checks for the host being requested, otherwise you'll get a redirect loop. For example, in the same olddomain.com/subfolder/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]
RewriteRule ^ http://www.newdomain.com%{REQUEST_URI} [R=302,L]
This redirects any request for olddomain.com/subfolder/<anything> to http://www.newdomain.com/subfolder/<anything>.
Again, change 302 to 301 when you are sure it's working OK.
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]
I have several domain aliases pointing to the same website like:
domain1.de/en/
domain1.de/de/
domain2.ch/de/
domain2.ch/en/
When someone opens a specific language-based sub-directory on a URL, I would like to redirect them to the start page, e.g. for domain1.de users shouldn't be able to access the sub-directory /en/ but be redirected to the start page. For the domain2.ch users should only have access to the directory /en/ and not /de/. How can I set this up with Htaccess?
This might be a helpful link to you;
htaccess redirect
for a 301 redirect entire directory it generated the following code:
//301 Redirect Entire Directory
RedirectMatch 301 domain2.ch/de/(.*) domain2.ch/en//$1
RedirectMatch 301 domain1.de/de/(.*) domain1.de/en//$1
Give this a try:
RewriteCond %{HTTP_HOST} ^de\.domain\.de$ [NC]
RewriteCond %{REQUEST_URI} ^(.*)/en/(.*)$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/targetpage.php [R=301,L]
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!
I should do internal redirects (301) for the list of pages.
Firstly when user opens / or /index.php he should be redirected to em.php, places in root folder. When user opens /contents/about_us/index.php he should be redirected to about_us/enterprise.php
Sound simple but I still can't to solve
When I use this
Redirect 301 / http://foo2.bar.com/service
Redirect 301 /index.php http://foo2.bar.com/service
it works.
But when I try this
Redirect 301 / http://www.site.com/em.php
I'm getting http://www.site.com/em.phpem.phpem.phpem.phpem.phpem.phpem.phpem.phpem.php ...
What's wrong with my code?
Your Redirect is going into a loop.
Do this instead either in a .htaccess file in DocumentRootor in your virtualhost section.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule ^ /em.php [L,R=301]