rewrite all pages /en/XXX to /en - linux

It's been a while since I've been busting my head to do a htaccess rewrite.
I would like to redirect all the pages from example.com/en/XXX to example.com/en.
I'm doing either redirection loops or errors 500.
Is it possible to help me to find the right formula?
I tried RewriteRule ^en/(.+)$ /en/ L,QSA
also this RewriteRule ^/en\/.*$ http://example.com/en/$1 [R=permanent,L]
Do you also know good links to learn htaccess and rewrite?
thank you in advance for your help

You need to put a condition to stop Looping, could you please try following once, base on your shown samples only.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/en/.*/?$ [NC] [L]
RewriteRule ^(en)/.*$ http://example.com/$1 [NC,L]
Merci RaVinder pour ton aide ! <3

Related

.htaccess multiple redirects with fallback

I'd like to create some kind of redirection script using .htaccess to map short urls (like example.com/1 to other urls). To do so, I've created this:
RedirectPermanent /1 https://www.youtube.com/watch?v=...
RedirectPermanent /2 https://www.youtube.com/watch?v=...
So far, that's working. However, it's missing a fallback. I'd like to add a 404 page that is shown whenever someone tries to navigate a URL that doesn't have any redirect (yet).
I've tried adding this:
...
RewriteCond %{REQUEST_URI} !^/404.html$
RewriteRule .* /404.html [L,R=302]
Obviously, this isn't working, because now ALL calls are redirected to 404.html. I thought about adding the redirects as conditions, but since there might be many redirects that approach seems very bad to me.
What can I do instead?
Thanks for helping out.
I've done this now, but I'm not sure if this is the best solution.
Please comment if you have any advices.
RewriteRule ^/1$ https://www.youtube.com/watch?v=1 [L,R=301]
RewriteRule ^/2$ https://www.youtube.com/watch?v=2 [L,R=301]
RewriteCond %{REQUEST_URI} !^/404.html$
RewriteRule .* /404.html [L,R=302]

How to mod-rewrite language parameter (e.g. ?lang=en) to fake subdomain (e.g. en.mydomain.com)?

It's so hard being a noob. I need someone to help me do this :-(
So basically, I need users to use this url:
en.mydomain.com <- very nice!
instead of using:
www.mydomain.com/index.php?lang=en
I know this is serious .htaccess stuff. Which I may never get my head around without any help. So, Thanks a lot.
You can place this rule as your very first rule in root .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)lang=en(&|$) [NC]
RewriteRule ^$ /index.php?lang=en [L,QSA]

htaccess mods rewrite

Newby to htaccess mods , thankyou for any help
I'm tryin to rewrite the following into a more efficient solution
RewriteRule about http://www.website.co.uk/index.php?/page/about [NC,L]
RewriteRule testimonials http://www.website.co.uk/index.php?/page/testimonials [NC,L]
I want the user to enter
www.website.co.uk/page/about etc
Can anybody advise, have spent a couple of hours on this & getting nowhere fast!!
Thansks
If those are the only two pages you need to redirect use
RewriteRule (about|testimonials) /index.php?/page/$1 [NC,L]
If you want to serve all your pages like that use
RewriteRule ^page/(.*)$ /index.php?/page/$1 [NC,L]

How to avoid htaccess redirect-rewrite loop?

My current htaccess does two simple url rewrites for two simple page. Here is the code.
RewriteEngine On
RewriteRule ^home/?$ index.php#home [NC,L]
RewriteRule ^contact/?$ index.php#contact [NC,L]
now mywebsites.com and mywebsite.com/home are the same pages. I am using the twitter bootstrap carousel to flip slide between page without actually loading them.
Unfortunately the number of facebook share on mywebsite.com/home is 2000 and on mywebsite.com/ is 29. So I want to 301 redirect mywebsite.com/ to mywebsite.com/home but that puts the htaccess into an infinite loop.
any help will be widely appreciated.
The following should allow for only ONE redirection.
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
Does that help?

isapi Rewrite For Just One Folder

I have a phycical folder at /shop/cart-plugins/subscription-wizard/. To make it easier for users find I have set up the following rule in my htaccess file to turn this into /join/.
It works great if they type in www.mywebsite.com/join/, but if they don't type in the last slash mark it doesn't do anything. I've looked all over google, but can't figure it out. Any advice you might have would be greatly appreciated.
Here's the rule I have set up.
RewriteRule ^shop/cart-plugins/subscription-wizard? /join/$1 [NC,R=301,L]
RewriteRule ^shop/cart-plugins/subscription-wizard/? /join/$1 [NC,R=301,L]
RewriteRule ^shop/cart-plugins/subscription-wizard/(.*) /join/$1 [NC,R=301,L]
RewriteRule ^join/(.*) /shop/cart-plugins/subscription-wizard/$1 [QSA]
Thanks...
RewriteRule ^join$ /join/ [L,R=301]

Resources