[英]Rewrite url to remove question mark and add slashes in htaccess
I've spent a couple of hours trying to achieve something I thought was easy. 我花了几个小时试图实现我认为很容易的事情。 I have http://localhost/testing_url_document/second.php?id=2
and want to turn it http://localhost/testing_url_document/second/id/2
. 我有http://localhost/testing_url_document/second.php?id=2
并想把它变成http://localhost/testing_url_document/second/id/2
。 I have achieved to remove the php extension but stucked into the rewriting the site page . 我已经实现了删除PHP扩展,但坚持重写网站页面。 In the htacces i have followed the following procedure. 在htacces中,我遵循以下程序。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
this is my index page 这是我的索引页面
Index.php 的index.php
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
// put your code here
?>
<a href="second/id/2">click here</a>
</body>
</html>
Second.php Second.php
<?php
echo $_GET['id'];
?>
The second.php should gets the value 2 second.php应该得到值2
Thanks in advance for help. 在此先感谢您的帮助。
Have it this way inside /testing_url_document/.htaccess
: 在/testing_url_document/.htaccess
里面这样/testing_url_document/.htaccess
:
RewriteEngine On
RewriteBase /testing_url_document/
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^./]+)(/.*)?$ $1.php$2 [L]
RewriteRule ^([\w-]+(?:\.php)?)/([\w-]+)/([\w-]+)/?$ $1?$2=$3 [L,QSA,NC]
This is the minimal configuration that can solve your problem: 这是可以解决您的问题的最小配置:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^site=(.*)$ [NC]
RewriteRule index.php /index/site/%1? [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.