Sorry I changed the previous question. I have problem with .htaccess rewrite rule on localhost, I have .htaccess file in http:// localhost/testing/.htaccess. I want to change url like below
http://localhost/testing/site.php?site=test
to
http://localhost/testing/test
And I have code in .htaccess as
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
Which is working correct, but I have also url like
http://localhost/testing/pages.php?site=test&pid=2
Here pages.php with two parameters as site name and page id. I want rewrite this as
http://localhost/testing/test/2
For both conditions I have bellow code which is not working
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
RewriteRule ^([^/\.]+)/?$ pages.php?site=$1&pid=$2 [L]
Please Help
Thanks :)
What you need to do is turn on the mod_rewrite
on your Apache
server by performing these steps:
Assuming you have unpacked the xampp
folder in the C:\\
directory, navigate to the folder containing the apache configuration files. The full path is C:\\xampp\\apache\\conf\\.
In the conf folder, you will find a file named httpd.conf
. This file holds all the configuration parameters for apache. Open the file in a text editor.
Search for mod_rewrite.so
and you will come across a line as follows : #LoadModule rewrite_module modules/mod_rewrite.so
Uncomment the line by removing the hash (#) mark.
Save the file and restart Apache web server.
and also if the file is already in the testing
folder your code should look like this:
RewriteEngine on
RewriteRule ^site\.html$ site.php?site_id=$1
I got solution which worked for me.
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
RewriteRule ^([^/]+)/([^/\.]+)/?$ pages.php?site=$1&pid=$2 [L,QSA]
Thanks everyone :)
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.