简体   繁体   English

隐藏URL htaccess的一部分

[英]Hide Part of URL htaccess

The Goal: 目标:

  1. The user lands on the site where the latest 10 articles are shown (no problem here). 用户登陆显示了最新10篇文章的网站(此处没有问题)。
  2. The user clicks on the title of one article using this href link in a table: 用户使用表中的以下href链接单击一篇文章的标题:

    <a href='"."article.php/".$type."/".$id."/".$web_title."'>".$title."</a>

  3. All links from any $type get directed to article.php . 来自任何$type所有链接都定向到article.php
  4. article.php should be built dynamically based on the $id retrieving information from the database. 应该基于从数据库检索信息的$id动态构建article.php

I've got this URL rewrite in my htaccess file: 我在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]

Which is producing the URL: http://example.org/article.php/news/1/first-article-test when the user accesses article.php via a link described in point 2. 当用户通过第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

I'm trying to remove the article.php section from the above URL, so it looks just like this: http://example.org/news/1/first-article-test 我正在尝试从上述URL中删除article.php部分,因此它看起来像这样: http://example.org/news/1/first-article-test : http://example.org/news/1/first-article-test

At the moment the article.php page is receiving the variables just fine, it's pulling down other data from the database based on the $id passed by the link, but the URL is displaying article.php/... . 目前article.php页面正好接收到变量,它正在根据链接传递的$id从数据库中提取其他数据,但是URL显示的是article.php/...

Keep your rule like this: 保持规则如下:

RewriteEngine On

RewriteCond %{REQUEST_FILE} !-f
RewriteCond %{REQUEST_FILE} !-l
RewriteCond %{REQUEST_URI} !^/article\.php [NC]
RewriteRule ^(.+)$ /article.php/$1 [L]

It will let you have your links as 它将使您的链接成为

http://example.org/news/1/first-article-test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM