Php 如何使用htaccess为clean URL重写URL(从URL中删除不必要的参数)
我正在为PHP项目开发localhost。我需要一些解决办法 当前URL:http://localhost/project/portfolio/php_files/port_sub_sidebar.php?x=opencart 现在,我想在URL中显示如下内容:http://localhost/project/portfolio/opencart 如何在.htaccess文件中进行更改Php 如何使用htaccess为clean URL重写URL(从URL中删除不必要的参数),php,.htaccess,url-rewriting,clean-urls,Php,.htaccess,Url Rewriting,Clean Urls,我正在为PHP项目开发localhost。我需要一些解决办法 当前URL:http://localhost/project/portfolio/php_files/port_sub_sidebar.php?x=opencart 现在,我想在URL中显示如下内容:http://localhost/project/portfolio/opencart 如何在.htaccess文件中进行更改 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f Re
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);
然后,您可以基于提供的段实现路由系统