I have a site where the issue has come up where I am getting a 404 error on a specific site URL with a query string. This isn't I a site I work on frequently so I am not sure if any queries should still be used. I tried this myself and it didn't work.
Redirect 301 /category.aspx?id=MISC34 /
I want the 301 direct to be specific to www.example.com/category.aspx?id=MISC34 to go to the homepage. This did not work for me. It is on Wordpress if that matters.
I am not that well versed in htaccess. Any help would be apperciated.
You can use in your .htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)id=MISC34(&|$) [NC]
RewriteRule ^category\.aspx$ /? [L,NC,R=301]
Related
While updating things in WordPress I found that plugins that generate slugs can't use a slug that's already in use by another page so I have had to change the slug to be something slightly different. I now need to make sure that anyone that tries the old urls get redirected to the new one without affecting the main page.
So I have /members/ with a list of members and you can click members to go to /member/[name] I need to redirect /members/[name] to the /member/[name]
( [name] can be anything so it needs to be a wildcard.)
I have used both of the following htaccess rules (not at the same time) but they always end up redirecting the /members/ page also which breaks everything.
RewriteRule ^members/(.*) http://domain.tld/member [R=301,L]
RedirectMatch 301 ^/members/.*$ http://domain.tld/member
What am I missing to make it only redirect if there's something after the /
Sidenote: I've tried finding an answer to this but all the results I have found are trying to do the exact opposite (redirecting only the exact match of /members/) that I need and wont work.
You are not using the captured part of the request.
Try :
RedirectMatch ^/members/(.+)$ /member/$1
Try this
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Redirect 301 /oldDir/old.php http://yourDomain/newDir/new.php
I'm having a problem with one of my rewrite rules. I would like to redirect all of the following URL's to another URL without the query string.
/gallery/products.aspx?C=9&SC=&ID=428&P=10
/gallery/products.aspx?C=2&SC=2&ID=128&P=1
/gallery/products.aspx?ID=147&C=2&SC=&P=7
/gallery/products.aspx?ID=1337&C=15&SC=&P=1
/gallery/products.aspx?ID=1532&C=3&SC=&P=2
/gallery/products.aspx?C=9&SC=&ID=1489&P=1
/gallery/products.aspx?C=7&SC=&ID=100&P=2
/gallery/products.aspx?C=2
/gallery/products.aspx?ID=1328&C=14&SC=11&P=17
/gallery/products.aspx?C=1&SC=&ID=767&P=3
/gallery/products.aspx?ID=1270&C=1&SC=&P=26
and I have this in my .htaccess file
RewriteRule ^gallery/products.aspx http://www.domain.com/category/? [L,R=301]
but it's not working. I checked it in a .htaccess simulator and it found the rule then redirected, but when I upload to my server, it doesn't redirect. I've also tried some other rules with no luck
I was finally able to make this work with the following:
RewriteCond %{HTTP_HOST} www.domain.com [NC]
RewriteRule products.aspx http://www.domain.com/category? [L,R=301]
I need to redirect traffic for a section of a redeveloped site back to the original site with apache mod_rewrite rules. I need to redirect all requests starting with http://www.example.com/page.asp back to the original site http://www.original.com/page.asp with the query string or anything following page.asp intact.
This seems simple enough, however I have had no luck with mod_rewrite generators or documentation on the web. My latest stab at the problem looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://www.example.com$ [NC]
RewriteRule ^page\.asp(.*)$ http://www.original.com/page\.asp$1 [R=301,NC]
I appreciate any insight into correcting this mod_rewrite rule. Other redirects are working fine.
I was able to get the rewrite to function properly using:
RewriteRule ^/page(.+) http://www.original.com/page$1 [R=301,NC,L]
I found this apache doc helpful: Resource Moved to Another Server
So I had an issue where my pagination would append a ?p=1 to the end of a URL when moving from page 2 back to page 1. With the issue corrected so those links no longer get served, I do have to try and find a way to do a 301 redirect from those URLs to the proper URL so that the search engines can update those links.
I am on an Apache server, and I would like to be able to use RedirectMatch 301 to do this, however I do not think that it plays well with query strings.
RedirectMatch 301 (.*)?p=1 http://mydomain.com/$1
does not do the trick
I believe the solution is going to end up being that I use RedirectCond and Rewrite statements to make this work, however I do not know how to get this to redirect.
Can someone help me out with this? What I have so far gives me Internal Server Errors so obviously I am not on the right track yet.
RewriteCond %{REQUEST_URI} (.*)$
RewriteCond %{QUERY_STRING} ^?p=1$
RewriteRule ^.*$ http://devserver/$1 [L,R=301]
If someone can even point me toward a good tutorial on how to set this up would be helpful too.
RewriteCond %{QUERY_STRING} (^|&)p=1(&|$)
RewriteRule . http://devserver%{REQUEST_URI}? [L,R=301]
I’ve written some code on my .htaccess file which allows the use of SEO friendly URLs instead of ugly query strings. The following code rewrites the SEO friendly version in the browser to the query string version on the server.
RewriteEngine On
RewriteRule ^seo/([^/]*)/$ /directory/script.php?size=large&colour=green&pattern=$1 [L]
So that the ugly
http://www.mysite.com/directory/script.php?size=large&colour=green&pattern=striped
Is now beautiful
http://www.mysite.com/directory/seo/striped/
Just to explain the code a bit; seo is there to add more keywords to the URL, /directory/ is the directory in which the .htaccess file is located, parameters size=large and colour=green never change, while pattern=$1 can be many different values.
The above code works perfectly. However, the problem is I am now stuck with two URLs that point to exactly the same content. To solve this, I would like to 301 redirect the old, ugly querystrings to the SEO friendly URLs. What I have tried so far does not work - and Google is not being particularly friendly today.
Can anybody offer working code to put in my .htaccess file that redirects ugly to new URL, while retaining the rewrite? Thanks!
This should do the trick:
RewriteEngine On
## Redirect to pretty urls
# The '%1' in the rewrite comes from the group in the previous RewriteCond
RewriteCond %{REQUEST_URI} !seo
RewriteCond %{QUERY_STRING} ^size=large&colour=green&pattern=([a-zA-Z]*)$
RewriteRule (.*) /directory\/seo\/%1\/? [L,R=301]
## Rewrite to long url, additional parameter at the end will cause
## the internal redirect not to match the previous rule (would cause redirect loop)
RewriteRule ^directory\/seo\/([^/]*)/$ /directory/script.php? size=large&colour=green&pattern=$1&rewrite [L]
You can also match the size and colour if needed, by changing those to regex groups as well, and using the corresponding %N
Hope this helps.
Not tested, but this may work...
RewriteRule ^directory/script.php?size=large&colour=green&pattern=(.*)$ /seo/$1/? [R=301,NE,NC,L]