Need 301 redirect rule in .htaccess file - .htaccess

I about to change an ecommerce store over from oscommerce to magento.
I have kept the url structure the same but need to rewrite the product and category urls.
I need this:
some-product-url-p-123.html
to be written to this:
some-product-url.html
and the category is the same principle:
some-category-url-c-123.html
to:
some-category-url.html
I have been trying to work this out and have spent hours looking but can't find anything. Any help would be great.

This pattern should work for you:-
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)?-[pc]-\d+\.html$ $1.html [NC,L]

Related

.htaccess - Redirect all .html capture the ID

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

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]

htaccess url aliases on custom website

Hello I'm developing a site with 5-6 pages like main.php(homepage), event.php(landing page of an event), article.php(another news landing page) etc etc etc...
I'm wondering how would it be possible to rewrite urls like "http://www.domain.com/event.php?eid=145" to something like "http://www.domain.com/event/title-of-event"
I've read a couple of articles on .htaccess but no luck yet currently I'm messing around with this but it's not what I want
Options +FollowSymlinks
RewriteEngine on
rewriterule ^event.php(.*)$ http://evented.localhost/event/$1 [r=301,nc]
Any help will be greatly appreciated or if you know of any decent url aliases tutorial for .htaccess.
Thnx.
EDIT:
This seems to work for event.php page it transforms a link into this http://domain.com/event/145 (according to the above example)
RewriteEngine on
#EVENT REWRITE
RewriteRule ^event/([^/\.]+)/?$ /event.php?eid=$1 [L]
RewriteRule ^event/(.*) /$1 [L]
How could I replace the event id with it's title ?
You'd have to.store the clean title with the other.data, then use the clean url to find the article.

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]

magento mod rewrite not working help wanted(htaccess) :)

my situation.....
i have this url http://www.example.com/index.php/category?catid=3
i want to have this rewritten to
http://www.example.com/bikes/3
my rewrites on the website are enabled....so i have nice urls on the website for the products
the pages i want to be rewritten are my own modules for pages with text
i have put this in my htaccess
RewriteRule .* index.php [L]
RewriteRule ^bikes/(\.*)/$ category?catid=$1
i have tried about any thing like 1000 combinations but nothing seem to work also i checked if my htaccess is working but it does.First line works also redirect to google works.
Hope someone is able to tell me what i am doing wrong here?
I had this example around here, and I think you can work it out to your needs:
Pretty URL: /topic-41/favourite-cheese.html
Ugly URL: /viewtopic.php?t=41
.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^topic-([0-9]+)/[A-Z0-9_-]+.html$ /viewtopic.php?t=$1 [NC,L]

Resources