I need to redirect a large amount of urls that are very similar to a single url so an example would be;
engagement-rings/marquise-cut-diamond-engagement-rings-4.html
engagement-rings/marquise-cut-diamond-engagement-rings-5.html
engagement-rings/marquise-cut-diamond-engagement-rings-6.html
engagement-rings/marquise-cut-diamond-engagement-rings-7.html
Would need to redirect to
/engagement-rings/marquise-cut-diamond.html
is there a simple bit of code that I could use to redirect?
e.g
Redirect 301 /engagement-rings/marquise-cut-diamond-engagement-rings-(*).html http://www.website.co.uk/engagement-rings/marquise-cut-diamond.html
Redirect directive doesn't accept Regular Expressions.
Use RedirectMatch directive instead:
RedirectMatch 301 (engagement-rings/marquise-cut-diamond).+?\.html$ /$1
OR else you can use this mod_rewrite rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine on
RewriteRule ^(engagement-rings/marquise-cut-diamond).+?\.html$ /$1 [L,NC,R=301]
Related
For an migration of a new website i need to redirect /example.html?id=2 redirected to /example/new-page.html
When i create an redirect like this:
Redirect 301 /example.html?id=2 https://www.url.com/example/new-page.html
Redirect 301 /example2.html?bla=34 https://www.url.com/example/new-page2.html
Redirect 301 /eteste.html?yolo=2 https://www.url.com/example/new-page3.html
It returned into this:
https://www.url.com/example/new-page.html?id=2
etc
Change it into this doesn't work either:
Redirect 301 /example.html?id=2 https://www.url.com/example/new-page.html?
Is there something i'm doing wrong (yes! ;))
You need to use mod_rewrite to match against the query string :
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=([^&]+) [NC]
RewriteRule ^example.html$ https://www.url.com/example/new-page.html? [NC,L,R]
My .htaccess look like as below
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^condos-([^-]*)-([^-]*)\.html$ /fm
/cond_new?r_id=$1&location=$2 [L]
The above URL is my old dynamic URL http://localhost/fm/condos-2-delhi.html
My new dynamic URL is http://localhost/fm/delhi/2/condos and .htaccess has below pattern
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /fm
/condo_new?location=$1&r_id=$2&name=$3 [L]
Now i want all URLs of pattern http://localhost/fm/condos-2-delhi.html shall redirect to http://localhost/fm/delhi/2/flavor with 301 redirect.
where flavor is name of product.
I tried as below but no success
RedirectMatch 301 ^condos-([^-]*)-([^-]*)\.html$ ^([^/.]+)/([^/.]+)
/([^/.]+)/?$
You can use this rule in /fm/.htaccess:
RewriteRule ^(condos)-([^-]+)-([^-]+)\.html$ /fm/$3/$2/$1 [L,NC,R=301]
Make sure this is your first rule below RewriteEngine On.
I need to use .htaccess file to replace a word in URL
something like this:
example URL:
http://domain.com/produts
redirect to:
http://domain.com/digital-tiles
how can i do it any idea??
That can be done in many ways as these:
Redirect 301 /products /digital-tiles
OR using RedirectMatch:
RedirectMatch 301 ^/products/?$ /digital-tiles
OR using mod_rewrite
RewriteEngine On
RewriteRule ^products/?$ /digital-tiles [L,R=301,NC]
I need help with how to use the htaccess when a folder and any subfolders get redirected to a new url.
Example: http:www.mysite.com/events/a-name-of-an-event (the 'a-name-of-an-event' will vary)
to
http:www.mysite.com/fixtures/
You can use RedirectMatch directive in your DOCUMENT_ROOT/.htaccess file:
RedirectMatch 301 ^/events/ /fixtures/
OR using mod_rewrite:
RewriteEngine On
RewriteRule ^events/ /fixtures/ [L,R=301,NC]
I'm trying to redirect http://domain.com/search to http://domain.com
However I also have urls that looks like http://domain.com/search?q=someword
At the moment I have :
redirectMatch 301 http://domain.com/search$ http://domain.com
And even though it redirects correctly the http://domain.com/search url, it also redirects any http://domain.com/search?q=someword url to http://domain.com/?q=someword, which I do not want.
What am I doing wrong?
I would suggest you to use mod_rewrite instead of mod_alias in your htaccess :
RewriteEngine On
RewriteBase /
RewriteRule ^search/?$ / [L,R=301]
Add a ? to the end of your target:
RedirectMatch 301 ^/search$ http://domain.com/?
This, however, will cause a ? to appear at the end of the URL in the browser's location bar. If you use mod_rewrite instead, you won't see the ?:
RewriteEngine On
RewriteRule ^/?search$ /? [L,R=301]