htaccess rule is not working on localhost

2019-06-28 02:48发布

问题:

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 :)

回答1:

You need to do is turn on the mod_rewrite on your apecha server by preforming these steps:

  1. 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\.

  2. 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.

  3. Search for mod_rewrite.so and you will come across a line as follows : #LoadModule rewrite_module modules/mod_rewrite.so

  4. Uncomment the line by removing the hash (#) mark.

  5. 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


回答2:

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 :)