I've been searching and searching for an answer and decided it may be best to ask. I am trying to redirect the following:
redirect 301 /store/?p=3m_controltac http://www.designtoprint.com/3m-controltac
I know it has something to do with using a GET variable but every example I've tried ends without success.
You cannot do this with Redirect directive as it does not work with GET variables. Your best choice is to use mod_rewrite (or implement it in your webpage (e.g. php file) directly):
RewriteEngine On
RewriteCond %{QUERY_STRING} =p=3m_controltac
RewriteRule ^store/$ http://www.designtoprint.com/3m-controltac? [R=301,L]
This will redirect (using 301 code) from /store/?p=3m_controltac to http://www.designtoprint.com/3m-controltac ONLY (no other URLs will be affected).
Related
What I'm trying to do is redirect example.com/author/authorname/ to example.com/author/authorname/page/1/ for the pagination to work more efficiently at the initial load of a page.
Currently I got
RedirectMatch /example/author/(.*) http://localhost:8888/example/author/(.*)/page/1/
I was trying to use a wildcard variable but that doesn't seem to work. In the first place where the (.*) is I would need to store that value as a variable and use that exact same name in the similar place in the redirection location.
Try:
RedirectMatch ^/example/author/([^/]+)/?$ /example/author/$1/page/1
or if you already have mod_rewrite rules, you should probably stick to that:
RewriteEngine On
RewriteRule ^example/author/([^/]+)/?$ /example/author/$1/page/1 [L,R]
I am sure this already exists, but I'm not too sure the terminology to search for exactly what I am looking for.
I have a url like http://www.example.com/members/$variable/achievements and I want all of these page to redirect to one level up, for example http://www.example.com/members/$variable.
I was originally using :
RewriteEngine On
RewriteRule ^members/([\w]*)/achievements/$ http://www.example.com [R=301,L]
which works fine for redirecting the original page to the homepage, but I would rather it go to that variable page.
RewriteEngine On
RewriteRule ^members/([^/]+)/achievements/?$ http://www.example.com/members/$1/ [R=301,L]
This assumes there is something after $variable/achievements (with and without the ending /) and redirect it back to http://www.example.com/members/$variable/
Please look at the edits on this post. The last code examples I give are what I'm trying to accomplish. I have 147 lines of code that I'm working with. I guess I'm actually not trying to make a rule so much as I am trying to figure out redirects with those variables.
OK, I've been researching this for a few hours, and the regex apache rewrite rules get pretty specific and I'm stumped. Client has asked that the old site urls be rewritten/redirected to the new drupal site and corresponding pages that have url aliases. There are 147 variables (all 1 - 216 (out of sequence))
Example:
I need
/hardware/bikes.php?recordID=1 to redirect to http://www.bikerus.com/?q=hardware/first-bike-that-really-flies
then
/hardware/bikes.php?recordID=2 to redirect to http://www.bikerus.com/?q=hardware/second-awesome-bike-that-really-flies
and so on
This is what I have so far:
RewriteCond %{QUERY_STRING} ^recordID=([0-9]+)$
RewriteRule ^/hardware/bikes\.php?recordID=%1$ http://www.bikerus.com/?q=hardware/first-bike-that-really-flies
This is obviously not working, any ideas ladies and chaps?
Ideally, it would be great if I could figure out another problem with Drupal I haven't figured out yet (for years).
Have a redirect that goes like this:
redirect 301 /hardware/1.html http://www.bikerus.com/hardware/first-bike-that-really-flies
Instead of this:
redirect 301 /hardware/1.html http://www.bikerus.com/?q=hardware/first-bike-that-really-flies
But my first question is the priority now.
Thanks in advance.
EDITS:
The files I'm trying to redirect to aren't static, they're url aliases generated by Drupal's database.
In the end, yes, I will need to make 147 individual records (hardcoded), my question is how to do this:
redirect 301 /hardware/bikes.php?recordID=1 http://www.bikesrus.com/?q=hardware/random-bike-title-one
redirect 301 /hardware/bikes.php?recordID=2 http://www.bikesrus.com/?q=hardware/random-bike-title-two-ewhbcfn
redirect 301 /hardware/bikes.php?recordID=3 http://www.bikesrus.com/?q=hardware/random-bike-title-three-kxjhmuflr
redirect 301 /hardware/bikes.php?recordID=4 http://www.bikesrus.com/?q=hardware/random-bike-title-four-more-random-stuff
And for those that don't know, Drupal has a clean url rewrite rule that comes shipped with the .htaccess file that I'm currently editing:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
So I need to be able to navigate this as well.
The problem to your second issue is that redirect really stinks for anything past a simple redirect. You need a RewriteRule to make this:
redirect 301 /hardware/1.html http://www.bikerus.com/?q=hardware/first-bike-that-really-flies
More like this:
RewriteRule ^([a-zA-Z]+)/$ /?q=$1 [R=301,L]
Or maybe this:
RewriteRule ^([a-zA-Z]+)/(.*)$ /?q=$1/$2 [R=301,L]
But it’s not clear in your post where you are getting the first-bike-that-really-flies stuff from. So not to clear on how to handle that in Drupal. Very specific to your setup.
Actually just answered a mod_rewrite question similar to this over here. Might give you more insight.
Just figured it out.
RewriteCond %{THE_REQUEST} recordID=1
RewriteRule . http://www.bikesrus.com/hardware/bike-that-really-flies? [R=301,L]
BOTH!! On my own, with a little more searching. The difference is that I put the word "hardcoded" into my search keywords this time. Thanks everyone who commented.
I am trying to figure out how to do a 301 redirect in my htaccess file to redirect some files to a new domain. Here's what I need to know how to do:
OLD URL: http://www.example.com/index.php?page=news&id=2366
NEW URL: http://www.example2.com/news.php?name=23546
The redirects don't have to be automatically created. I can hard-code the pages I need to redirect in the htaccess file, I just don't know the format to use as I've read that a "standard" 301 redirect won't work with query strings.
Basically this is what I want to do, but from my research so far it doesn't sound like it can be done this way.
redirect 301 /index.php?page=news&id=2366 http://www.example2.com/news.php?name=23546
You could use a rewrite rule with a query string match condition, such as:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{QUERY_STRING} ^page=news&id=2366$
RewriteRule ^(.*)$ http://www.example2.com/news.php?name=23546 [R=301,L]
Checkout this blog page for more information on how this works.
I had the same problem, but still more complicated, because I needed to discard other parameters.
Like this: my-old-page.php?a=1&b=2&c=3
I need to use one of the strings and discard the others, but that solution only worked if I want to use the last parameter (c=3). If I want to use any other (a=1 or b=2) it runs to a 404. After much struggling and searching, I found an answer:
RewriteCond %{QUERY_STRING} ^.* ?b=2.* ?$ (without space after the *)
RewriteRule (.*) http://www.my-webpage.php/new-location-2? [R=301,L]
The solution is to add ".*?" before and after the parameter to use.
I don't know if this is the best solution, but it works.
I'm trying to redirect an old url to a new one using 301
I need an example of RewriteQueryString for the following 301? http://www .example.com/search/?depId=1&typeCatId=1 to the following http://www.example.com/mens/clothing
So when I type in the long URL in the browser, I am redirected to the new, shorter URL
Any ideas?
RewriteEngine On
RewriteRule ^search/\?depId=1&typeCatId=1$ /mens/clothing [R=301]
^ Try that.
You could use mod_rewrite either in your .htaccess file or the apache configuration. You might take a look at the RewriteMap feature if you are going to have a lot of different departments, etc. to map. Using the [R] flag after the RewriteRule will cause the browser to redirect instead of just being an internal redirect. Using [R=301] will make it a 301 redirect.