how to let htaccess work on every page - .htaccess

I think there is an easy solutions to my problem, but I'm quite the noob when it comes to htaccess. So I'm asking for help.
RewriteRule ^home/([\w-]+)/?$ home.php?lang=$1 [NC,L,QSA]
This is my current code, and it works. But unfortunately, it only works on the page "home". And I want it to work on all pages of my URL. I've managed narrowing it down to this line:
RewriteRule ^/([\w-]+)/?$ ?lang=$1 [NC,L,QSA]
But it hasn't had any effect. So, could anyone help me with this?

You have to remove the leading slash from rule's pattern
RewriteRule ^([\w-]+)/?$ ?lang=$1 [NC,L,QSA]

Related

rewrite all pages /en/XXX to /en

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

htaccess: Rewrite with several variables

I want to redirect a page like
/topic/italian-page2.html to /index.php?s=italien$p=2
or
/topic/france-page4.html to /index.php?s=france$p=4
but also (without page number)
/topic/spain.html to /index.php?s=spain$p=1
Right now I use
RewriteRule ^topic/([a-zA-Z0-9\-]+).html$ /index.php?s=$1&p=1 [L]
RewriteRule ^topic/([a-zA-Z0-9\-]+)-page([0-9]+).html$ /index.php?s=$1&p=$2 [L]
The first one (without page) works fine.
The second one doesn't.
It redirects to /index.php?s=italian-page2&p=$2
What did I do wrong? Where is my mistake?
Thank you!
Found a solution:
RewriteRule ^topic/([a-zA-Z0-9]*)-page([0-9]*).html$ /?s=$1&p=$2 [L]
RewriteRule ^topic/([a-zA-Z0-9\-]+).html$ /?s=$1&p=1 [L]
That works!

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]

Remove string in .htaccess

I have the following entry in my .htaccess file:
RewriteRule ^blogs$ ?name=data&case=gview&group_id=31%1 [L]
What I do is, I redirect blogs to ?name=data&case=gview&group_id=31
Now what happens is, all my urls are now blogs?id=1 etc, but I need them to stay just ?id=1
How can I remove the blogs from rest of the urls?
This what I came up with, but it doesn't work:
RewriteRule ^blogs?(.*)$ /$1 [L]
EDIT I might be explaining it wrong. I need to change the actual url display of the links. Is that actually possible?
Not sure... but is that what you're looking for ?
RewriteRule ^/?$ /blogs [L,QSA]
What's wrong with just adding a R to your original rule?
RewriteRule ^blogs$ ?name=data&case=gview&group_id=31%1 [L,R=301]
Ok, the answer is pretty much: It can't be done. I just went over my code, added / before main urls and all is working as intended.
Thank you both for suggestions.

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