0

I have the problem, that I when I enter this into my browser:

http://localhost/myString

I can get myString by writing $_GET['id']. This works thanks to my following .htaccess file:

RewriteEngine on
RewriteRule ^/?([0-9a-zA-Z]+)$ /myFile.php?id=$1
FallbackResource /index.php

Now I want to add the possibility that users can change the default language. I want this to be possible by entering:

http://localhost/en/myString

myString should be accessible through $_GET['id'] and my language code with $_GET['lang'].

I am completely new to writing .htaccess configs so this is what I tried but didn't work:

RewriteEngine on
RewriteRule ^/?([0-9a-zA-Z]+)$ /chat.php?id=$1
RewriteRule ^/?([a-z]+)$/([0-9a-zA-Z]+)$ /chat.php?id=$2&lang=$1
FallbackResource /index.php
3
  • 1
    Note that $ signifies the end of the string to be matched. A basic example might be: RewriteRule ^([a-z]+)/([0-9a-zA-Z]+)$ Commented Jul 30, 2019 at 21:43
  • If the language is optional, you might try: RewriteRule ^(?:([a-z]{2})/)?([0-9a-zA-Z]+)$. Here's an explanation. Commented Jul 30, 2019 at 21:55
  • Also see Rewrite URL with .htaccess for multiple parameters. Commented Jul 30, 2019 at 22:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.