简体   繁体   中英

I want to hide id from url using htaccess in PHP

I'm trying to hide URL id
from
http://localhost/download/view.php?s_id=T7bPo
to
http://localhost/download/view/T7bPo

ReWriteEngine On

RewriteRule ^view/([0-9]+) view.php?s_id=$1

I tried many lines of code like

RewriteRule ^view/([^/\.]+)?$ /view.php?s_id=$1  [L]
RewriteRule ^view/+?$ /view.php?s_id=$1  [NC,L]

But failed everytime

Error Object Not Found

As you can see below
在此处输入图片说明

If your .htaccess file is in /download/ folder check this rule on top of your rules:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^view\/(.*)$ /view.php?s_id=$1 [L]
</IfModule>

If your .htaccess file is in / website root folder check this rule on top of your rules:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^download\/view\/(.*)$ /download/view.php?s_id=$1 [L]
</IfModule>
#remove php file extension-e.g. https://example.com/file.php will become https://example.com/file
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

from https://www.plothost.com/kb/how-to-remove-php-html-extensions-with-htaccess/

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