301 htaccess redirect from old path to new path - apache

I want to the following redirect 301 to happen on .htaccess file for my site.
From:
www.mysite.com/view/2133/page.html
To:
www.mysite.com/node/2133
The 2133 will be a dynamic number like a * (eg www.mysite.com/view/*/page.html)so it will work for all my other pages.

Try:
RewriteEngine On
RewriteRule view/([0-9+]) /node/$1 [R=301,L]
For an explanation see: URL Aliasing, Redirection, Rewriting and Reverse Proxying using Apache HTTPD

Related

htaccess redirect only specific page, not subpages

I have a website with following url structure:
www.example.com/products
www.example.com/products/productA
www.example.com/products/productB
I need to redirect www.example.com/products to www.example.com but www.example.com/products/productA and productB should still be available.
Does anyone have an idea?
At the top of your .htaccess file, using mod_rewrite:
RewriteRule ^products$ / [R=302,L]
I've used mod_rewrite here, as opposed to a mod_alias RedirectMatch directive since I assume you are already using mod_rewrite later in the file to rewrite your URLs. It is preferable not to mix redirects/rewrites from both modules.
Reference:
https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriterule

convert nginx redirect to .htaccess apache (drupal 7)

I have to redirect url in .htaccess:
original: /mobile/blog/
redirect : /blog/
I tried:
RewriteCond %{REQUEST_URI} ^/mobile/blog/
RewriteRule ^mobile/blog/(.*)$ /blog/$1 [R=301,L]
Without success.
I aslo have these nginx redirect that need to be in .htaccess.
rewrite ^/items/(.+)/(.*) /search/$2 permanent;
rewrite ^/items/(.*) /search/$1 permanent;
rewrite ^/topic/onlyon $scheme://$host/tags/onlyon permanent;
Any help and documentation is appreciated.
Since Drupal sometimes updates the .htaccess file and Drupal often maintains a set of redirect internally it often makes sense to handle redirects using the Redirect module.
That said, if you need or want to do redirects in the .htaccess you can do that just fine. The first redirect you can do without rewrite, you can use Apache's redirect directive:
Redirect permanent /oldlocation /newlocation
To move everything in a directory using rewrite you can use something like this:
RewriteRule ^items(/.*)?$ /search/$1
See also: Apache rewrite rule for whole directory

htaccess apache rewrite rule

I had a script that ran weather update urls in /weather which is now deleted
These types of urls are 404'ed and need to be redirected to /index.php as I show below
www.atlanticcity.com/weather/index.php?config=&forecast=pass&pass=local_radar&dpp=1&radar_icao=karx&hwvradartype=comp&place=wisconsin+rapids&state=wi&zipcode=&country=us&county=55141&zone=WIZ035
This I tried and doesnt work....
RewriteRule ^weather/(.*) http://www.atlanticcity.com [R=301,L]
You could use a redirect rule instead of rewrite. This would have to go in the apache .conf file under the virtual hosts tag.
Redirect 302 /weather/.* http://www.atlanticcity.com/index.php

Redirecting all sub-sub pages to another subpage using htaccess

I've a older site running in Apache Server which is already indexed in Google. I wish to redirect all those indexed links to my new site (As the older pages are not existing any more.)
So i wish to redirect all my sub-sub pages to my new root page
I've pages like follows
http://itdost.com/answer-now/Aerobics
http://itdost.com/answer-now/HTML
http://itdost.com/answer-now/Culture
I use the following redirect code for each one
Redirect 301 /answer-now/Engineering http://www.itdost.com/questions/
Redirect 301 /answer-now/Food http://www.itdost.com/questions/
Redirect 301 /answer-now/ASP http://www.itdost.com/questions/
But as the site structure is big, i wish to do it in a single line instead of writing a line for each redirect
Some thing like the following.
Redirect 301 /answer-now/% http://www.itdost.com/questions/
But the above code does not seems to work
In order to use regex better to use mod_rewrite which is more powerful than mod_alias.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^answer-now(/.*|)$ http://www.itdost.com/questions/? [L,NC,R=301]
Try this:
RedirectMatch 301 ^/answer-now/ http://www.itdost.com/questions/

Simple 301 redirect in .htaccess with query string does not work with Redirect directive

I am trying to redirect a single URL in a .htaccess file with Redirect:
Redirect 301 /index2.php?option=com_rss&feed=RSS2.0&no_html=1 /something/somethingelse/
I have a bunch of other similar rules which work using directory structure URLs, but this one refuses to get processed.
Redirect 301 /old/url/ /new/url/
Do I have to do anything special?
Thanks!
With Redirect you can only test for URL paths, or more specifically, URL path prefixes but not for the URL query. But you can do so with mod_rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} =option=com_rss&feed=RSS2.0&no_html=1
RewriteRule ^index2\.php$ /something/somethingelse/? [L,R=301]