htaccess - insert additional path - .htaccess

I need to insert an additional path to an URL an forward it by 301. An example:
Old URL: http://example.com/products/cf1/
NEW URL: http://example.com/products/additional-path/cf1/
I tried the this:
RewriteRule ^/?products/[^additional-path]*(.*)$ /products/additional-path/$1 [L,R=301]
How can I achieve this?

To redirect /product/foobar to /product/path/foobar , you can use the following rule
RewriteRule ^/?product/([^/]+)/?$ /product/path/$1 [L,R=301]
Clear your browser cache or try a diffrent browser to test this.

Related

Rewrite url via htaccess on apache server

I have a url which is
www.domain.com/index.php?route=ticketsystem/generatetickets
I want people who type in the url www.domain.com/contact to be redirected to the page index.php?route=ticketsystem/generatetickets however have the url bar still show /contact is that possible via htaccess and if so how? I tried the below
RewriteEngine On
RewriteBase /
RewriteRule contact /index.php?route=ticketsystem/generatetickets [L,QSA]
For your shown attempts, please try following .htaccess rules file. Make sure your index.php and .htaccess files are present in same directory/folder. Also better to use & rather than using / for query string.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^contact/?$ index.php?route=ticketsystem&generatetickets [QSA,NC,L]

Remove all parameters from specific URL

How do I get this original URL:
https://www.example.com/search-for-commercial-doors.html?format=json&task=suggestions.suggest&tmpl=component
To be rewritten to:
https://www.example.com/search-for-commercial-doors.html
Code that is not working:
RewriteEngine On
RewriteRule ^search-for-commercial-doors\.html$ /search-for-commercial-doors.html? format=json&task=suggestions.suggest&tmpl=component [L]
With your shown samples, please try following htaccess Rules file. Make sure your htaccess file is present along with search-for-commercial-doors.html in same folder, also clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond ^(search-for-commercial-doors\.html)/?$ $1?format=json&task=suggestions.suggest&tmpl=component [NC,QSA,L]

How can I 301 redirect a URL with variables in it (.htaccess)?

I have the following URL:
https://www.parcelparcel.com/nl_NL/pakket-versturen-frankrijk/?page=nl_NL/populair/pakket-naar-frankrijk/
Which I would like to 301 redirect to:
https://www.parcelparcel.com/nl_NL/pakket-versturen-frankrijk/
I tried to pull this off with the following code in my .htaccess:
RewriteRule ^index.php/populair/pakket-naar-frankrijk/?page=nl_NL/populair/pakket-naar-frankrijk/?$ https://www.parcelparcel.com/nl_NL/pakket-versturen-frankrijk/ [R=301,L]
However, without results. Can anybody advice me or tell me what I'm missing. I checked if the URL is redirected in incognito.
Thanks in advance!
Try This:
RewriteCond %{QUERY_STRING} !^(.*)$
RewriteRule ^nl_NL/pakket-versturen-frankrijk/?$ nl_NL/pakket-versturen-frankrijk/?page=nl_NL/populair/pakket-naar-frankrijk/ [L]
Fisrt line to exclude a request that has Query String
The second to choose a URI that starts with nl_NL/pakket-versturen-frankrijk/ or nl_NL/pakket-versturen-frankrijk and redirect it internally to nl_NL/pakket-versturen-frankrijk/?page=nl_NL/populair/pakket-naar-frankrijk/

htaccess to remove part of a url, .htaccess

I was wondering how it is possible to remove part of a url with htaccess for example I have a url like this:
http://localhost/item.php?pa=gd34392
now I need to use htaccess to redirect this page or anything like this to a page with this url:
http://localhost/gd34392
I have tried things like this but nothing seems to work and I do not really know my way around htaccess
RewriteEngine on
RewriteRule item.php?pa=$1 /$1 [R=301,L]
You can achieve that using the following rules in your .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /item.php?pa=$1 [L]
Just make sure you clear your cache before testing this.

Using Mod_Rewrite to redirect from one URL to another

I want to route anyone trying access:
www.domain.com/shop_en/proddetail.php?prod=333
To the following URL:
www.domain.com/shop/product/333
how can I do this?
Add the following lines to your .htaccess file:
RewriteEngine On
RewriteRule ^/?shop/product/([^/d]+)/?$ shop_en/proddetail.php?prod=$1 [L,QSA]

Resources