.htaccess - Redirect all .html capture the ID - .htaccess

I am facing the following problem:
I have a website in which the URLS currently look like:
/manufacturer/product/[ID].html
I have re-developed the website (Using Laravel) and now it just is:
/product/[ID]
I am wondering whether it is possible to use a .htaccess file to redirect all these links back to the new link? So, in essence, I would need to just capture the [ID] from the old link and redirect it back to the new link.
EDIT:
So the link will look something like this:
mysite.com/parts/apple/A-6-H0.htm
OR
mysite.com/microsoft/A-1-5F.htm
So both Apple, Microsoft and A- can change depending on what manufacturer and what the product is Does this make sense?

RewriteEngine On
RewriteRule ^parts/(?:[^/]+/)?(.*)\.html?$ /parts/$1/ [R=301,L]
That should take care of it.

Please Try this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^{domain name}[nc]
RewriteRule ^(.*)$ {domain name}/$1 [r=301,nc]
Redirect 301 /manufacturer/product/$1.html product/$1.html

Related

htaccess is working but does not replace the url

I'm trying to modify the subdomain name in the URL to make it look nicer. My current URL look something like:
www.mystore.com/productInfo.php?cPath=11_11&productID=222
So, I want to make it nicer by Rewrite in .htaccess in main with this code:
RewriteEngine On
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]
When I run and test it on the URL by typing www.mystore.com/productInfo/11_11/222 in the URL it works well. However, when this page is redirected by a different page or is 'refreshed' with a self redirecting a href= link(in which the link is written in php by the previous programmer), the above old link is still visible in the URL instead of the new one.
I am still a beginner while I suspect that I might need to change something in the cPanel/Apache(I think) for this but currently, I am still do not have access to the cPanel control. Is there anything that I might have missed to write in the .htaccess file or I really do need the cPanel control or any other reasons?
Any help is appreciated. Sorry that I could not find similar questions on this.
You can use the following :
RewriteEngine On
RewriteBase /
#redirect /productInfo.php?cPath=foo&productID=bar to /productInfo/foo/bar
RewriteCond %{THE_REQUEST} /productInfo\.php\?cPath=([0-9_-]+)&productID=([0-9_-]) [NC]
RewriteRule ^ productInfo/%1/%2? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]

Url rewriting in .htaccess file in Joomla Site

I want to write a rule in .htaccess file, all I want to do it:
The user will look for following link:
www.example.com/sitemap.xml (in browser address bar)
but in reality I want to show the following link:
www.example.com/index.php?option=com_xmap&view=xml
Try this
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/sitemap\.xml$
RewriteRule .* /index.php?option=com_xmap&view=xml [QSA,R,L]
You need to use mod_rewrite. There are lots of details in the official docs. If you don't want the user to see the new URL in the address bar, you should use an internal redirect.
RewriteEngine on
RewriteRule "^/sitemap\.xml$" "/index.php?option=com_xmap&view=xml" [PT]

htaccess mask a range of URL's to more readable versions but show content from original URL

Here is a sample of filter URL's on an ecommerce store.
http://www.domain.com/showering/showers/filter/alliance
http://www.domain.com/showering/showers/filter/aquaflow
http://www.domain.com/showering/showers/filter/grohe
http://www.domain.com/showering/showers/filter/mira
I'm wondering if there is a way I can mask these URL's so they appear like:-
http://www.domain.com/alliance-showers
http://www.domain.com/aquaflow-showers
http://www.domain.com/grohe-showers
http://www.domain.com/mira-showers
But still display the page content from the /showering/showers/* URL's?
I then wish to be able to set the canonical URL's based on these masked URL's.
I've played around with countless variations with little success but here is something I've got so far:-
RewriteEngine on
RewriteCond %{HTTP_HOST} !^/showering/showers/filter/(alliance)
RewriteRule (.*) /alliance-showers/
When this is applied to website, all the images on the Magento store don't load incidentally along with the fact that the URL doesn't change at all.
Answer to #anubhava's comment...
.htaccess file is in root or Magento installation. It is the very first rule in file like so:-
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^-]+)-([^/]+)/?$ /showering/$2/filter/$1 [L,R]
Currently testing with this URL:-
http://www.showermania.co.uk/showering/showers/filter/alliance
Wanting to show as:-
http://www.showermania.co.uk/alliance-showers
Current answer has no affect/change on this URL at all. Thanks.
You can use a rule like this:
RewriteEngine on
RewriteRule ^showering/([^/]+)/filter/([^/]+)/?$ /$2-$1 [L,NC]

rerwrite url in .htaccess

I want to make the old urls point to the new pages. I'm having trouble because the old URL looks like this: http://nilandsplace.com/store/camping_eng/coghlans-campfire-cooking-forks-toaster-forks-package-of-4.html.
I want to do a URL re-right in .ht access from mywebsite.com/camping_eng/some.html to mywebsite.com/camping/some.html, were the "some.html" part is identical.
Only camping_eng changes to camping.
You might want to try this:
RewriteEngine on
RewriteRule ^camping_eng/([a-zA-Z0-9-=_.]+)/?$ http://mywebsite.com/camping/$1 [L,R=301]
This example works according to your question:
from mywebsite.com/camping_eng/some.html
to mywebsite.com/camping/some.html were the "some.html" part is identical.
RewriteEngine on
RewriteBase /store
RewriteRule ^camping_eng/(.*)$ camping/$1 [QSA,L,R=301]

Redirect .html but not .html?with=options

I'm currently using an .htaccess to get round a problem with a CMS, nothing major and an htaccess fix is tidy enough.
I'm currently using the format...
redirect 301 /pictures.html http://www.domain.com/gallery.html
The problem though this causes is that the CMS uses pictures.html?vars=here to select galleries and so the redirect breaks this part of it. Is there any way I can redirect pictures.html but not when it has variables attached?
For example, add something like
RewriteCond %{QUERY_STRING} ^$
before your rule.
You can redirect everyone except your webserver by detecting the IP address like so:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^123\.45\.67\.89
RewriteRule \.html$ /alternate_page.html [R=301,L]

Resources