htaccess redirection for a pattern - .htaccess

I searched for a solution of my issue and tried several ways but none of them worked.
I am migrating my website to a new system and want to change the url structure too. But I couldnt find a solution for one of them which is the most important one.
It is an e-commerce site. All product page urls had domain.com/product/productname/ in the previous system and now I need them to go to domain.com/productname.html . So the product part should be catched and redirected to the version without product/ .
Might be very simple too but I couldnt find a solution for that.
Thanks in advance
Cheers

You can use this simple rule in your site root .htaccess:
RedirectMatch 301 ^/product/([^./]+)/?$ /$1.html

Related

How to redirect old file urls using TYPO3 v9

Currently a TYPO3 website of ours has had a complete revamp and we would like to redirect all the old URL's in Googles index to the new existing URL's
For regular pages I used the new site management tool (Redirects) in TYPO3 v9. However what is left is the old indexed links of the content.
www.websitename.com/content/docs/this-is-my-document.pdf and so on. Including images and other miscellaneous links to files.
Now what would be the best way to redirect those links?
I could use htaccess ofcourse or is there something in the TYPO3 core/Extbase what I could be able to use?
I would always prefer redirects with mod_rewrite in the .htaccess file since it's much faster than any TYPO3 solution. If the redirect is done via .htaccess, there is no need for the webserver to invoke PHP or the database. Thus it's faster.
Found out we stopped rewrites by default for URL's with:
RewriteRule ^(typo3/|content/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L]
By removing the 'content/' I was able to use the redirect functionality from the core. This was done so we could manage redirects through the TYPO3 enviroment in the future.
as Peter said above it would be faster to use .htaccess but we would like for it to be more manageable in the future through the system. So we chose the core option.

Htaccess crashing my site

Having a problem with adding a .htaccess to one of my sites, whether I leave it blank or use code from a working .htaccess from another site I'm getting the same error 500 and my website goes down.
Could anyone point me in the right direction as to where the problem may be? Seems to be the two differences between my sites working with .htaccess and the ones not - Do you need a public_html to have a .htaccess? Or is it to do with hosting? Or something else?

.htaccess file - Rewrite rules not working with new hosting

I have been using the following in the root of my hosting with (123-reg) for sometime now i have since moved to Godaddy and the rules not longer seem to work. I have contacted their support and they said that they follow the defaults for linux mod-rewrite rules and they believe there is a problem with my scripting...?
here is what i am using:
RewriteEngine On
RewriteRule ^fishing/$ fishing.php [L]
I have alot more rules within .htaccess but will pick this one just as an example.
When i was with 123-reg i could simply type in http://domain.com/fishing and it would load the fishing.php file.
On godaddy this goes straight to 404. Can anyone see anything obvious going on here?
For info: It works fine if i type in the full path: http://domain.com/fishing.php but this is not what i want.
Also can anyone confirm that this is a standard rewrite rule and should work with the defaults of apache mod-rewrite rules?
Turns out for some reason you have to add:
Options -Multiviews
to your .htaccess file for it to work.
Would be helpful if the techs at GoDaddy knew this information though. I have seen this on many forums on the internet about a similar problem with godaddy. Hope this helps someone else.

Htaccess redirect

Hey folks, I'm migrating a website over a to new CMS with a different URL structure, I'd like to have users redirect if a specific part of the link is missing. So if the user goes to www.domain.com/articles/name_of_article it'll take them to the old site, however if they go to www.domain.com/ it'll forward them to the subdirectory http://beta.domain.com
So what I'm trying to accomplish is to leave the old URLs active as to not lose traffic from old links since migrating those links is impossible because of how the old CMS was coded..but prompt the user to move over to the new site when they land on those pages.
how can this be accomplished via htaccess, any tips will be greatly appreciated?
Regards and thank you for your help!
RewriteEngine on
RedirectMatch ^/$ http://beta.domain.com/
did it
...The answer was a lot simpler than the question hah

.htaccess in my project

Hai
I want to know how to use .htaccess in my project. I know simply write the URL in to .htaccess file. After that what is the next step? what I will do to redirect the url ??
.htaccess configuration files can allow you to do lots of things -- ie, not only redirections.
For more informations, the first place you can take a look is Apache Tutorial: .htaccess files, which should give you a couple of ideas of what .htaccess files are, and when you should use them.
After that, depending on what your hosting provider allows you to do, there are several other things you might be able to do, like, for instance :
Redirections
activation/deactivation of caching
activation/deactivation of content gzipping
...
About Redictions, the basic idea is to :
define the conditions upon which redirection should occur
write down the RewriteRule that will do the redirection itself.
You'll be able to find some documentation under Apache mod_rewrite, and Apache Module mod_rewrite.

Resources