如何使用htaccess重写URL为干净的URL(从URL删除不必要的参数)


How to rewrite URL using htaccess for clean url (remove unnecessary parameter from url)

我正在为PHP项目的本地主机工作。我需要一些解决办法。

当前URL: http://localhost/project/portfolio/php_files/port_sub_sidebar.php?x=opencart

现在,我想在URL中这样显示:http://localhost/project/portfolio/opencart

怎么可能在。htaccess文件中做改变

In .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(.*)('.jpg|'.gif|'.png|'.css|'.js)$
RewriteRule ^(.+)$ index.php?url=$1 [L,QSA]

你可以通过下面的代码获得url

$url = $_GET['url'];
$segments = explode("/",$url);
print_r($segments); 

,那么你就可以基于提供的段

实现你的路由系统