[英]Hide Part of URL htaccess
目标:
用户使用表中的以下href
链接单击一篇文章的标题:
<a href='"."article.php/".$type."/".$id."/".$web_title."'>".$title."</a>
$type
所有链接都定向到article.php
。 $id
动态构建article.php
。 我在htaccess文件中重写了该URL:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/article/?
RewriteCond %{REQUEST_FILE} !-f
RewriteCond %{REQUEST_FILE} !-l
RewriteRule ^(.*)$ article.php?post_type=$1&post_id=$2&post_name=$3 [QSA,L]
当用户通过第2点中描述的链接访问article.php
时, article.php
生成URL: http://example.org/article.php/news/1/first-article-test
: http://example.org/article.php/news/1/first-article-test
。
我正在尝试从上述URL中删除article.php
部分,因此它看起来像这样: http://example.org/news/1/first-article-test
: http://example.org/news/1/first-article-test
目前article.php
页面正好接收到变量,它正在根据链接传递的$id
从数据库中提取其他数据,但是URL显示的是article.php/...
保持规则如下:
RewriteEngine On
RewriteCond %{REQUEST_FILE} !-f
RewriteCond %{REQUEST_FILE} !-l
RewriteCond %{REQUEST_URI} !^/article\.php [NC]
RewriteRule ^(.+)$ /article.php/$1 [L]
它将使您的链接成为
http://example.org/news/1/first-article-test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.