RewriteRule .htaccess - .htaccess

I'am trying to update .htaccess to redirect me from : page.php/name to page.php?id=name. Can anyone help with example? I find a lot of example but not for this case.

To redirect (telling the browser that the request for page.php/name is at page.php?id=name, thus changing the URL in the location bar) you can do one of two things.
Using mod_alias:
RedirectMatch 301 ^/page\.php/(.*)$ /page.php?id=$1
Or using mod_rewrite:
RewriteRule ^/?page\.php/(.*)$ /page.php?id=$1 [QSA,L,R=301]
If you don't want a permanent redirect (301), then remove the 301 and =301 parts from the above.

Related

How to implement 301 permanent redirection using htaccess with custom parameter in URL?

Here I have a URL like www.abc.com/product/women/casual/page:5/ and I need to implement 301 permanent redirection using htaccess in order to change the URL to www.abc.com/product/women/casual/page/5/. In this case, parameter women and casual is customized category and subcategory and page:5 is page number 5. I need to change the last parameter page:5 to page/5 using htaccess 301 permanent redirection. Can anyone please help me to find a solution for the case.
You can use the following redirect :
RedirectMatch 301 ^/([^:]+):5/$ /$1/5/
Or a more generic one:
RedirectMatch 301 ^/([^:]+):([0-9])/?$ /$1/$2
This will redirect your old URL to the new one , for example example.com/foo/bar:digit/ to example.com/foo/bar/digit/ .
Or you can use RewriteRule directive
RewriteEngine on
RewriteRule ^([^:]+):5/$ /$1/5/ [R=301,L]

Redirect all urls which contain certain parameters to another url which follows a certain pattern

Unfortunately I didn't get it solved by myself and need to ask for help. I want to redirect all urls which follow a certain pattern (in this case it contains "reviews/category"). These URLs supposed to be redirect to another url which is made up the first one:
http://[product-url]/reviews/category/[category-url]
supposed to be redirect to
http://[product-url].html
Furthermore it shouldn't matter if you call the url with or without www.
Example:
http://example.com/ford-blues/reviews/category/cars supposed to be redirect to http://example.com/ford-blues.html
Any help would be much appreciated.
Following code isn't working
RewriteEngine On
RewriteRule ^reviews/category/?$ $1\.html [R=301,L]
Try:
RedirectMatch 301 ^(.*)/reviews/category/ /$1.html
in the htaccess file in your document root.
Or using mod_rewrite:
RewriteEngine On
RewriteRule ^(.*)/reviews/category/ /$1.html [L,R=301]

301 redirection in htaccess

I am creating htaccess for my site I need to redirect old urls to new url through 301 redirect. I have created code in htaccess as follows
My old urls like
www.example.com/categories/city/cityname/brandname/product1.html
and my new url is like
www.example.com/product1.html
For this scenario I have written following code in htaccess
RedirectMatch 301 ^/categories/city/cityname/(.*)$ http://www.example.com/$1
Please help me regarding this scenario or where I am doing wrong.
Try using mod_rewrite's functionality in your .htaccess like this:
RewriteEngine On
RewriteRule ^/categories/city/cityname/(.*)$ /$1 [R=301,L]
Referring to #Seybsen answer, this 1 line should fit all your needs :
RewriteRule ^/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/(.*)$ /$5 [R=301,L]

301 redirect any page to one specific page

IS there a way with just htaccess 301 redirect to redirect any page on a domain to a specific page on another domain.
eg. I was domain.com/index.html and domain.com/contact.html to both redirect to newsite.com/index.html
But I am wanting to do this without having to list each of the pages specifically.
can my 301 redirect be just something like
301 * http://newsite.com/index.html
or how should it be set up. Unfortunately I don't have access to mod rewrite so I cant use mod rewrite to make it work.
Had an issue similar to this using wordpress and trying to remove all .asp extensions from pages, this worked pasted at the top of my .htaccess file
## 301 Redirects
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.asp$ $1? [R=301,NE,NC,L]
Yes, that is possible -- instead of mod_rewrite you need to use mod_alias (which has more chances to be enabled).
This one will redirect everything to index.html on newsite.com/
RedirectMatch 301 ^/(.*)$ http://newsite.com/index.html
This one will redirect everything to the same path but on another domain: (e.g. oldsite.com/meow.php => newsite.com/meow.php)
RedirectMatch 301 ^/(.*)$ http://newsite.com/$1

301 redirect urls

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.

Resources