I need some help trying to redirect a query to a url.
www.example.com/?categoryID=79
needs to redirect to
www.example.com/catname
where catname is just a string, it has no variables.
Here's what I tried so far:
I began with a humble approach that failed horribly:
redirect 301 /?CategoryID=79 http://www.example.com/catname/
then i moved on to mod_rewrite :
RewriteCond %{QUERY_STRING} CategoryID=79$
RewriteRule (.*) /catname/? [R=301,L]
Both did not work and I'm actually stomped.
any help would be appreciated.
Just to be clear, In the end i'll have many of these rules redirecting to various category names.
important - it's not enough for /catname to display the proper page, the request with the query parameter must redirect to the new url.
This rule should work for you as first rule in your .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+\?CategoryID=79[&\s] [NC]
RewriteRule ^ /catname/? [R=302,L]
Related
I'm trying to create some 301 redirect rules, but just don't have the syntax understanding to make it work. I've seen lots of examples, but can't get my specific case to work.
Old URL sample:
/new-products-display.cfm?asset=ION2810040N&c=ION&s=281
Redirect to new URL structure plus asset parameter (remove additional query parameters)
https://example.com/inventory/product-display/?asset=ION2810040N
Below is my current best try, but I just can't get it to work quite right.
RewriteCond %{QUERY_STRING} ^asset=([^&]+)&c=([^&]+)&s=([^&]+)$ [NC]
RewriteRule ^(.*)$ /inventory/product-display/%1? [R=301,L,NE]
Any help would be greatly appreciated!
You may use this rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(asset=[^&]+)(?:&|$) [NC]
RewriteRule ^new-products-display\.cfm$ /inventory/product-display/?%1 [R=301,L,NE,NC]
Make sure to test it after clearing your browser cache.
I'm trying to redirect http requests that contain a specific URI to a different domain with a different URI completely. Redirecting the top level domain works but I can't seem to get the URI rules to redirect.
In essence it should act as follows:
If the url request is:
www.example.com/unique-URI
it needs to redirect to:
https://example2.com/anotheruniqueURI
Currently I have this:
RewriteEngine On
#This redirect works successfully
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ http://example2.com/something [R=301,L]
#This attempt to redirect requests with the specific URI does not work.
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteCond %{REQUEST_URI} ^/cars-application$ [NC]
RewriteRule ^/(.*)$ https://example2.com/anotherURI/ [R=301,NC,L]
I've tried many different combinations inside my RewriteRule such as explicitly stating the URI like I did in the RewriteCond above but that doesn't work. Using $1 here won't apply since I'm redirecting to a completely different domain and URI. The URI's I am expecting will be unique. Could you guys provide me some pointers. Is my regex correct or is my rewrite rule capture just wrong?
Your rule failed to work due to the leading slash in your RewriteRule's pattern . Remove the slash to fix it.
RewriteRule ^(.*)$ https://example2.com/anotherURI/ [R=301,NC,L]
Assuming you are redirecting from within a virtualhost of the first domain, you may just do the following:
Redirect permanent /unique-URI http://www.domain2.com/newlocation
I can't figure out how to redirect all query urls to another location.
Example:
I want to redirect all urls that follow this pattern:
https://www.test.com/index.php?option=com_sobipro&pid=[any numbers]&sid=[any numbers]&itemid=646
To new location: https://www.test.com/some/place/
I've googled for hours trying to learn and this is what I've come up with so far but I'm not sure this is right.
RewriteCond %{QUERY_STRING} option=com_sobipro&pid=(.*)&sid=(.*)&itemid=646$
RewriteRule ^$ /some/place/ [R=301,L]
How to check a requested (and dead) url for pattern and send it to another adress if conditions are met using htaccess? Any guidence would be grately appreciated.
Place this rule as your top most rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} option=com_sobipro&pid=[^&]+&sid=[^&]+&itemid=646
RewriteRule ^ /some/place/? [R=301,L]
I'm trying to create a URL redirect but so far everything I have tried just hasn't shown any effect on the site. I know ModRewrite is enabled as there are other rewrites taking place. The whole purpose of this is to handle old URLs from the former version of the website.
What I want to achieve is a redirect of a URL with the following format:
/resources/view?id={id} and redirect it to /resources/{id}.
I've been trying to do so with variants of this:
RewriteRule ^resources/view?id=([0-9+])$ /resources/$1 [R=301,L]
and also this:
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^/resources/view$ /resources/$1? [R=301,L]
Cheers.
You can use these 2 rules in your site root .htaccess:
Options -MultiViews
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /resources/view\?id=(\d+) [NC]
RewriteRule ^ /resources/%1? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^resources/(\d+)/?$ resources/view?id=$1 [L,QSA,NC]
I'm looking for an htaccess rule to 301 redirect an old domain search result page, to a new domains result page keeping only the "query" parameter.
For example: change from http://myoldwebsite.com/search?query=free+templates&type=post&submit= to http://mynewwebsite.com/?s=free+templates.
I've found a method of redirecting each url manually, but I'm thinking there is an easier way to accomplish this using a single rule.
Can anyone point me in the right direction?
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?myoldwebsite\.com$ [NC]
RewriteCond %{QUERY_STRING} (?:^|&)query=([^&]*)(?:&|$) [NC]
RewriteRule ^search/?$ http://mynewwebsite.com/?s=%1 [L,NE,R=301]