I have old site with hundreds URL that look like that:
http:www.domain.com/Contact.asp?Pid=344
http:www.domain.com/Contact.asp?Pid=345
http:www.domain.com/Contact.asp?Pid=346
and so on ...
I need to move all of them permanent to 1 single URL :
http:www.domain.com/contact
I tried this:
RewriteCond %{QUERY_STRING} Contact.asp?Pid=([0-999]+)
RewriteRule ^http://www.domain.com/contact? [L,R=301]
But it doesn't work well.
The old site use ASP. The new site build on Joomla. The domain will be the domain from old site
You're close. You need to use the %{QUERY_STRING} variable like you did, but the var doesn't include the URI-path (the Contact.asp?) part. Also, your RewriteRule is missing a regex pattern. Try:
RewriteCond %{QUERY_STRING} Pid=([0-999]+)
RewriteRule ^/?Contact\.asp$ http://www.domain.com/contact? [L,R=301]
RewriteRule ^Contact.asp?Pid=(\d) /contact? [L]
Are the only pages you have on there the contact pages? You could just 301 the entire directory since they are all moving to one URL.
RewriteEngine on
RewriteBase /
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]
Related
I have a domain
http://www.example.biz/
I developed a site and put the code in a sub folder on this domain for example, the site is at
http://www.example.biz/site
now, I wanted to point my main domain to this folder so that when user visits example.biz he actually sees example.biz/site and for that, I added the below lines in .htaccess
RedirectMatch ^/$ /site/
it works perfectly however, the url user sees is
http://www.example.biz/site
I do not want that, I wanted user to only see http://www.example.biz as URL but this domain should point to the sub folder invisibly. How should I do that ?
Using mod_rewrite you can use the below rule, now when you access http://www.example.biz it will show the index file from for site/.
RewriteEngine On
RewriteRule ^$ /site/ [L]
Or if you want to show every file try with below,
RewriteEngine On
RewriteRule ^(/|.+)$ site/$1 [L]
I found a simpler solution,
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.biz$
RewriteRule !^site/ /site%{REQUEST_URI} [L]
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'm trying to set 301 redirects on pages that have 'page=1' in the URL to stop duplicate content issues.
e.g.
http://www.domain.com/reviews/?page=1
to
http://www.domain.com/reviews/
I've tried all of the variations I can find and can't seem to get anything to work.
RewriteRule ^reviews(/)?page=1$ http://www.domain.com/reviews/ [L,R=301]
RewriteRule ^(.*)/?page=1 http://www.domain.com/reviews/ [R=301,L]
RewriteCond %{QUERY_STRING} page=1
RewriteRule ^reviews$ http://www.domain.com/reviews/ [R=301,L,NE]
None of these have worked. I'm not really sure what else to try.
There are multiple different sections of the site that I need to do this for:
reviews
news
videos
accessories
hardware
An overall solution to redirect all ?page=1 URLs to their relevant section would be best.
Use this code to redirect every URI with ?page=1 to one without the query parameter:
RewriteCond %{QUERY_STRING} ^page=1(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L]
Or else if you want to redirect ONLY /reviews URI then
RewriteCond %{QUERY_STRING} ^page=1(&|$) [NC]
RewriteRule ^(reviews)/?$ /$1? [R=301,L]
the question is already answered, i just would like to mention that your rules are not working because you didn't append a trailing ? to the new url in the rewrite rule
I gave an old website a new CMS. Now i need a .htaccess with 3 parts, but it only works with 2 of them:
Redirect permanent
www redirect (this don't work)
url rewriting
Now i 'll explain something more.
Part 0 (only for the totality)
RewriteEngine On
Part 1 (Redirect permanent) i use to redirect the URLs of the old CMS to the content of the new one.
RewriteCond %{THE_REQUEST} !/de-old-content.html
Redirect permanent /de-old-content.html /old/content.html
Part 2 (www redirect) i use to avoid duplicate content.
RewriteCond %{HTTP_HOST} ^website.de [NC]
RewriteRule ^(.*)$ http://www.website.de/$1 [L,R=301]
Part 3 (url rewriting) to convert "old/content.html" into "index.php?adresse=old/content"
RewriteRule ^(.*)\.html$ index.php?adresse=$1 [l,qsa]
the [l,qsa] only allows to use $_GET.
Is it possible to combine this parts?
If i use Part 2 it shows the right content with
http://www.website.de/abc/def/ghi.html
but without www it redirect to
http://www.website.deabc/
I think there must be a misstake in this Part.
Thanks in advance.
Redirect is part of mod_alias, while RewriteCond and RewriteRule are part of mod_rewrite. As a consequence the RewriteCond of part 1 accually applies to the RewriteRule of part 2, which would make it not work properly.
Best to avoid using both rewriterule and redirect together.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^website.de [NC]
RewriteRule ^(.*)$ http://www.website.de/$1 [L,R=301]
RewriteRule ^de-old-content\.html$ /old/content.html [L,R=301]
RewriteRule ^(.*)\.html$ index.php?adresse=$1 [L,QSA]
PS. to keep your sanity, use 302's while testing. Once everything is working, change them to 301's. Since you already used 301's, also clear your browser cache, so all the old 301's are removed from the browser's cache.
Damn you modrewrite
I have a website hosted at a url like:
http://mydomain/mocks/thesite/
Now I want to move it to a new domain
http://thesitesdomain.com/
My htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule (.*) http://www.thesitesdomain.com/$1 [R=301,L]
Now this works fine as long as there is something after /mocks/thesite/. eg: http://mydomain/mocks/thesite/index.html redirects to http://www.thesitesdomain.com/index.php.
However the problem is that:
http://mydomain/mocks/thesite/ redirects to http://thesitesdomain.com/mocks/thesite/. Any idea why? How to stop this?
The .htaccess file is in the root of /mocks/thesite/ (if that helps)
Thank you
You should try to use the variable REQUEST_URI you might have a little more success with that. It should be the request uri and file name. To
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI} [R=301,L]
I can't remember but to also redirect with the query string (get variables) I think you need to add it like this.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]
Been a while since really doing a domain redirect....
BTW this is a good read on htacces configuration:
http://corz.org/serv/tricks/htaccess2.php