I need to redirect an entire site from the following structure:
http://www.example.com/01/01/2001/post
to
http://newsite.com/example/post
I found the following code, but was worried that it would point the redirect to the new site and include that date category in the permalink. I have already migrated the site successfully without the date category showing on the new site.
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^www\.newdomain\.com
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Will the above work, or will it point to a 404 because it redirects to the new site with the date category included, which doesn't exist?
Thanks for your thoughts on the best solution to this.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example)\.com$ [NC]
RewriteRule ^[0-9]+/[0-9]+/[0-9]+/([^/]+)/?$ http://newsite.com/%1/$1 [R=301,L,NE]
Reference Doc: Apache mod_rewrite Introduction
Related
I need to redirect a few specific dynamic php pages to an external website domain. For example,
siteA.com/home/space.php?uid=357&do=thread&id=396
to
siteB.com
I put the following in my .htaccess but it didn't work.
Options +FollowSymlinks -MultiViews
RewriteEngine On
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
what's wrong with this? any suggestion is appreciated. thanks!
From this:
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
to this:
RewriteRule ^[home/space.php?uid=357&do=thread&id=396]+$ http://www.siteB.com [R=301,L]
You need to use RewriteCond for matching query string:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{QUERY_STRING} ^uid=357&do=thread&id=396$ [NC]
RewriteRule ^home/space\.php$ http://www.siteB.com [L,NC,R=302]
I recently changed from an ASP site to a PHP site and I need to rewrite the old URL style to a new style. For example:
www.mydomain.com/store/list_view.asp?itemid=1000645
To this:
www.mydomain.com/store/list_view.php?id=1000645
so far I can get an ASP request to redirect to a PHP page using this:
RewriteEngine on
RewriteRule ^(.*)\.asp$ /$1.php [R=301,NC]
I'd appreciate any help that you can provide and if possible an explanation of how it works, I'm new to working with redirects and .htaccess.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^itemid=(.+)$ [NC]
RewriteRule ^(.+?)\.asp$ $1.php?id=%1 [R=301,L,NC]
It matches QUERY_STRING for itemid parameter and captures it's value in %1 via RewriteCond. Then it replaces .asp by .php and adds id=%1 to complete the target URL.
The crawling properties of site showing
http://www.abc.com/http://www.abc.com/index.php?option=com_toys
http://www.abc.com/http://www.abc.com/index.php?option=com_article
http://www.abc.com/http://www.abc.com/index.php?option=com_play&view=category&vid=10
The site been crawled like this, with errors coming in as duplicate url. Correct url is
http://www.abc.com/index.php?option=com_toys
http://www.abc.com/index.php?option=com_article
http://www.abc.com/index.php?option=com_play&view=category&vid=10
is there any way to 301 redirect
i tried using
RewriteCond %{REQUEST_URI} ^.*/http://www.abc.com.*$
RewriteRule .* index.php [R=301,L]
But its not achieving the desired as redirecting to http://www.abc.com/index.php
How to redirect through htaccess from incorrect url to correct url sttructure off site
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+http://.+?(/index\.php\?[^\s]+) [NC]
RewriteRule ^ %1 [R=301,L,NE]
Try this code :
RewriteEngine On
RewriteRule ^http://www.abc.com/index.php /index.php [QSA, R=301]
Recently moved a site over from a subdomain into a subdirectory of the root domain.
http://blog.domain.com to http://domain.com/blog.
I dropped this into my .htaccess at http://blog.domain.com, so users going to articles with old URLs will be redirected accordingly.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://blog.\domain\.com
RewriteRule .* http://domain.com/blog [R=301,L]
I am unable to figure out how to redirect http://blog.domain.com to http://domain.com/blog. The snippet above does not do that. Any insights would be greatly appreciated!
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.domain\.com$
RewriteRule ^(.*)$ http://domain.com/blog/$1 [L,R=301]
I need to 301 redirect all ?print=yes URLs to the URLs without ?print=yes that contain the same name in them through .htaccess. Currently the button to PRINT is present in the header of the website so it's more than 70 URLs to fix... Removing the button to PRINT the page will ruin the design quite a bit, so it's not really an option.
I think it needs to be a RedirectMatch rule, but how do I write it?
Example: redirect 301 from domain.com/faq/?print=yes to domain.com/faq
Thanks in advance!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^print=yes$ [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L,NE]
I am not sure if redirect can do the same but here is how I would do it with rewrite
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\?print=yes$ $1 [NC]