简体   繁体   中英

Hide Part of URL htaccess

The Goal:

  1. The user lands on the site where the latest 10 articles are shown (no problem here).
  2. 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>

  3. All links from any $type get directed to article.php .
  4. 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/... .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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