htaccess redirect ugly multi lang url - .htaccess

I am trying to change my ugly urls from this:
domain.com/page.php?lang=en
domain.com/page.php?lang=al
into this:
domain.com/page.php (when it's english)
domain.com/al/page.php (when it's albanian)
I have tried many answers from other stackoverflow solutions but none worked for me.
Anyone can help me solve this?

For domain.com/page.php?lang=en use:
RewriteEngine On
RewriteRule ^page\.php$ /page.php?lang=en [L]
For domain.com/page.php?lang=al use:
RewriteEngine On
RewriteRule ^al/page\.php$ /page.php?lang=al [L]

Related

Transform(redirect) URL segment to a GET parameter

I know this has probably been answered but I can't find anything specific to my issue.
I have URLS like this:
https://staging.books.co.za/travelguide/route-map/SAFI546754
https://staging.books.co.za/travelguide/route-map/SAFI189444
https://staging.books.co.za/travelguide/route-map/SAFI978634
and I need them to be redirected to URLS like this:
https://staging.books.co.za/travelguide/route-map?reference=SAFI546754
https://staging.books.co.za/travelguide/route-map?reference=SAFI189444
https://staging.books.co.za/travelguide/route-map?reference=SAFI978634
Please help...What would the rule look like in my .htaccess file???
This should do the trick:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^travelguide/route-map/(.+) /travelguide/route-map?reference=$1
See here for a demo http://htaccess.mwl.be?share=6c2be57a-6bb7-5083-9122-aaf63162b240
Try and use this in your .htaccess:
RewriteEngine On
RewriteRule ^travelguide/route-map/([-a-zA-Z0-9_]+)/?$ route-map?reference=$1 [L]
Make sure you clear your cache before testing this.

Mod_Rewrite with .htaccess is not working

I just learnt about url-rewrite for my website with .htacess. My actual url is:
localhost/index.php?view=some-page
So i write this RewriteRule like this:
RewriteRule ^/([^/]*)/?$ /index.php?view=$1 [NC,L]
When i typed localhost/homepage on my browser, It does not work, it displays error 404 object not found. What have i done wrong please show me.
Many thanks
This should work in your DocumentRoot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?view=$1 [QSA,L]
Leading slash is not matched in htaccess.
are you using apache?
This link from step 6 helped me
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04
When i was playing around with rewrites i had to enable it and tell apache where the pages were stored

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.

ht access mod_rewrite query string append flag

I'm using these two lines in my htaccess to direct /something to /page.php?page=something. I'd like /something?key=value to translate to /page.php?page=something&key=value.
These lines do not seem to be working.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [R,QSA]
RewriteRule ^([a-zA-Z0-9]+)$ /page.php?page=$1 [L,QSA]
Any ideas on how to improve this?
I've fixed the problem. It actually wasn't working because of another rule in the htaccess file which wasn't written correctly. The code above works fine. Thanks.

Mod_Rewrite RewriteRule issue

I have a domain at example.com
There is a subdirectory that has a quiz on it, located at example.com/quiz/?id=1
I need to change the ?id=1 to TakeTheQuiz so it would look like example.com/quiz/TakeTheQuiz
Here is what my .htaccess looks like right now (the .htaccess is located in the root direct at example.com). Right now I always get a server 500 error.
RewriteEngine On
RewriteBase /quiz
RewriteRule ^?id=1$ TaketheQuiz
This is really simple and all of the examples I have seen have been really complicated and hard for me to apply it to this one :( Help, anyone? Thank you for your time.
You've just got the rule the wrong way round:
RewriteEngine On
RewriteBase /quiz
RewriteRule ^TaketheQuiz$ ?id=1 [L]
EDIT
Per your comment try this instead:
RewriteCond %{QUERY_STRING} id=1
RewriteRule ^$ TaketheQuiz [R=301,L]

Resources