0

I'm trying to rewrite a url from the website that I made but I'm not an expert using .htaccess. Basically I'm trying to do this:

Localhost test environment ( WAMP ):

http://127.0.0.1/project/index.php?p=home&l=en

into this:

http://127.0.0.1/project/en/home/

I made something like this but I know it is not correct:

RewriteEngine on
RewriteRule ^$2/$1/$ /index.php?p=$1&l=$2 [L]

What's the correct way to achieve this?

2 Answers 2

1

You can't use $1, $2, etc. in the pattern. You must use parenthesis like so :

RewriteRule ^(.+)/(.+)/$ /index.php?p=$2&l=$1

In the rewrited URL, $1 and $2 correspond respectively to the parenthesis in the order they appear in the regular expression.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm testing on my localhost using wamp and nothing works. The rewrite module is enabled
Do you get an error 500 or it's simply not working ? Could you try a basic rewrite like RewriteRule test.php index.php to see if the problem comes from your rule or from the module.
0

also You can try with this following

RewriteRule ^([0-9A-Za-z]+)/([a-zA-Z0-9_-]+)$ /index.php?p=$2&l=$1 [L,QSA]

1 Comment

I must change my answer because something is not working in my test environment

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.