We have moved from IIS to Apache and used the below rewrite rule to redirect www.example.co.uk/Default.aspx?pagename=About-Us to the new page url www.example.co.uk/About-Us/
RewriteCond %{REQUEST_URI} ^/Default\.aspx$
RewriteCond %{QUERY_STRING} ^pagename=About-Us$
RewriteRule ^(.*)$ http://www.domain.co.uk/About-Us/ [R=301,L]
The problem is this rule is showing up as duplicate content in google WMT and the page is being served at both URL's...
Can anyone spot what is wrong with this rule?
Change your rule to this:
RewriteCond %{QUERY_STRING} ^pagename=About-Us$ [NC]
RewriteRule ^Default\.aspx$ http://www.domain.co.uk/About-Us/? [R=301,L,NC]
Also note that it will take some time for search bots to remove duplicate URIs.
Related
I would like to write a rule in my .htaccess to rewrite the url to enable my subdomain to show the content of a page from my site.
For example, I would like http://subdomain.example.org/page to show the content of the page http://example.org/subdomain/page.
I tried to write some rules as follow but it did not work
RewriteCond %{HTTP_HOST} ^subdomain.example.org$
RewriteCond %{REQUEST_URI} !^/subdomain/
RewriteRule ^(.*)$ /subdomain/$1 [L]
RewriteCond %{HTTP_HOST} ^subdomain.example.org$ [NC]
RewriteRule ^((?!subdomain).*)$ example.org/subdomain/$1 [NC,L]
Those rules end up raising an Internal Server Error
I also tried the last rule
RewriteCond %{HTTP_HOST} subdomain.example.org
RewriteRule ^(.*)$ http://example.org/subdomain$1 [L]
But this rule end up redirecting to http://example.org/subdomain and not just showing the content of the page while keeping the url.
What should be the right way to write the rule ?
Further to an earlier question I had where I needed to rewrite urls such as
http://example.com/index.php?cPath=371_1659_1660&main_page=products_categories
to
http://example.com/index.php?cPath=371_1659_1660
I used this to fix it
RewriteCond %{QUERY_STRING} ^(.)(^|&)main_page=products_categories(.)$
RewriteRule ^(.*)$ /$1?%1%3 [R=301,L]
I've also discovered that I also have the same urls as https so
https://example.com/index.php?cPath=371_1659_1660&main_page=products_categories
and
http://example.com/index.php?cPath=371_1659_1660&main_page=products_categories
are giving me duplicate page penalties
Is it possible to modify my rewrite rule so that it also redirects to the http page at the same time as removing the
&main_page=products_categories
suffix so that
https://example.com/index.php?cPath=371_1659_1660&main_page=products_categories
would become
http://example.com/index.php?cPath=371_1659_1660
Not sure why this question was unfairly down voted.
You can use this single rule to redirect both URLs to http://...:
RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)main_page=products_categories(?:&|$) [NC]
RewriteCond %{QUERY_STRING} (?:^|&)(cPath=[^&]+) [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}?%1 [R=301,L,NE]
i want to redirect specific urls from
http://www.domain.com/com/page.asp?id=99
to
https://www.domain.com/de/directory/
and all urls from
http://www.domain.com/com/page.asp
to
https://www.domain.com/de/
ive tried some redirects but i cant get it done right.
Please help me!
RewriteCond %{query_string} id=5
RewriteRule (.*) https://www.domain.com/de/directory/? [R=301,L]
this works, but the biggest problem is all urls in the cms https://www.domain.com/cms are redirected too if they contain an id
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=99$
RewriteRule ^page\.asp$ /de/directory/ [L,R]
RewriteRule ^page\.asp$ /de/ [L,R]
I'm combining a main site at www.domain.com, and an old wordpress blog at blog.domain.com, into one completely new Wordpress install. I have exported and imported all the old blog posts so that they now live under wwww.domain.com/blog//
I am trying to create one rewrite rule that will map all the old blog posts to their new URLS.
I've tried variations on these SO discussions:
DNS/.htaccess files to redirect subdomain to specific folder
Apache rewrite rule different if capture is empty
but nothing is working.
The following in my .htaccess file will redirect blog.domain.com to www.domain.com/blog, if there is nothing more in the URL:
RewriteCond %{HTTP_HOST} ^blog\.domain\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.blog\.domain\.com$ [NC]
RewriteRule ^/?$ http://www.domain.com/blog/$1 [R=301,L]
but if there is anything more in the URL, it does not rewrite the URL at all, and goes to the new Wordpress site's 404 page.
I tried adding a capture to the final RewriteRule line, but then no rewrite occurs, and it just goes to the new homepage but the address bar still reads "blog.domain.com":
RewriteCond %{HTTP_HOST} ^blog\.domain\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.blog\.domain\.com$ [NC]
RewriteRule ^/(.+)$ http://www.domain.com/blog/$1 [R=301,L]
Is there a way to do what I'm trying to do?
You want to remove the leading slash:
RewriteCond %{HTTP_HOST} ^blog\.domain\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.blog\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/blog/$1 [R=301,L]
# no slash---^
And make the + a *. URI's that are sent through rules in htaccess files have the leading slash stripped off, so ^/(.+)$ would never match.
Replace your rule to this:
RewriteCond %{HTTP_HOST} ^(www\.)?blog\.domain\.com$ [NC]
RewriteRule ^ http://www.domain.com/blog%{REQUEST_URI} [R=301,L]
PS: Make sure this is the 1st rule in your .htaccess.
I have a URL
http://test.devsite-1.com/test/tbox/
which I want to redirect to
http://tbox.devsite-1.com/
Rule:
RewriteCond %{HTTP_HOST} !^tbox\.(.*)$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.|)(.*)$ [NC]
RewriteCond %{REQUEST_URI} ^/tbox(/.*|)$
RewriteRule /tbox/(.*) http://tbox.%{HTTP_HOST}/$1 [R=301,L]
I don't understand why it is not redirecting me to the URL? Please note I need a generalized rule so that if I change test.devsite-1.com to tempo.devsite-1.com the same should work with the other URL as well.
Try this rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.(.+)$ [NC]
RewriteRule ^test/tbox/(.*)$ http://tbox.%1/$1 [R=301,L]
This will redirect (301 Permanent Redirect)
http://test.devsite-1.com/test/tbox/something-optional
to
http://tbox.devsite-1.com/something-optional
It has to be placed in .htaccess file in website root folder (e.g. http://test.devsite-1.com/.htaccess). If placed elsewhere some tweaking may be required.
It will only work if request is coming via test. subdomain.
And it will only work if URL requested starts with test/tbox/.
All of the above matches your URL examples.