I'm developing a frontend/backend application using PHP/MySQL. The project is almost done but I want to mask the variables displayed on the URL but something is not working on my WAMP local server.
mod_rewrite
is active in Apache.
Below I provide us the information needed:
http://127.0.0.1/bookstoreSystem/index.php?page=home&language=en
I want to transform the URL above into:
http://127.0.0.1/bookstoreSystem/en/home/
I used the following code in the .htaccess file:
RewriteEngine on
RewriteRule /^([^/]*)/^([^/]*)/\.php index.php?page=$1&language=$2
beyond this, when I run this code and tried to see the site, nothing changes or not working
What's the correct way to achieve this?
/ ***** /
The .htaccess is placed on this path:
c:/wamp/www/
and the project folder
c:/wamp/www/bookstoreSystem
Your code is a bit confusing:
RewriteEngine on
RewriteRule /^([^/]*)/^([^/]*)/\.php index.php?page=$1&language=$2
What is that \\.php
supposed to be?
Try this instead:
RewriteEngine on
RewriteRule ^([a-z0-9-_]+)/([a-z0-9-_]+)/?$ index.php?page=$1&language=$2 [L]
Also, unclear about where in your system the .htaccess
will be placed based on this URL:
http://127.0.0.1/bookstoreSystem/en/home/
So it might be best to shift the captured parameters over by one number; to $2
and $3
instead if $1
and $2
:
RewriteEngine on
RewriteRule ^([a-z0-9-_]+)/([a-z0-9-_]+)/?$ index.php?page=$2&language=$3 [L]
EDIT: The original poster now says:
The .htaccess is placed on this path:
c:/wamp/www/
and the project folder
c:/wamp/www/bookstoreSystem
Two solutions. First, just take the .htaccess
and place it in c:/wamp/www/bookstoreSystem
.
Or keep the .htaccess
in c:/wamp/www/
and just use this reworked RewriteRule
:
RewriteEngine on
RewriteRule ^([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)/?$ index.php?page=$2&language=$3 [L]
Note the three capture areas of ^([a-z0-9-_]+)
. That captures all three segments, but the rule then only uses $2
& $3
. Which means that bookstoreSystem/
gets discarded, but en/home/
is acted on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.