问题
The Goal:
- The user lands on the site where the latest 10 articles are shown (no problem here).
The user clicks on the title of one article using this
href
link in a table:<a href='"."article.php/".$type."/".$id."/".$web_title."'>".$title."</a>
- All links from any
$type
get directed toarticle.php
. article.php
should be built dynamically based on the$id
retrieving information from the database.
I've got this URL rewrite in my htaccess file:
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.
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
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/...
.
回答1:
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
来源:https://stackoverflow.com/questions/24041964/hide-part-of-url-htaccess