Php 如何根据URL中的get变量重定向URL
我正在尝试根据get变量更改我的网站URL,以便提高网站的安全性 例如,我想更改我的地址,这是我的htaccess文件:Php 如何根据URL中的get变量重定向URL,php,regex,.htaccess,Php,Regex,.htaccess,我正在尝试根据get变量更改我的网站URL,以便提高网站的安全性 例如,我想更改我的地址,这是我的htaccess文件: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /category.php?cat_id=$1&mode=full&start=$1 我的网址是: http://joinexam.in/cat
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /category.php?cat_id=$1&mode=full&start=$1
我的网址是:
http://joinexam.in/category.php?cat_id=17&mode=full&start=36
我想将此URL转换为:
http://joinexam.in/category/1736
- 其中cat_id=17
- 和开始=36
category.php
页面之后,它将变成1736
,我正在尝试使用.htaccess文件来实现它
这里我想把cat_id
和start
都作为get变量,然后根据这些get变量,我想更改我网站的URL
有人能解释一下实现这一目标的正确方法吗?.htaccess 这会将每个URL转发到index.php
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
PHP
获取index.php中的“原始”URL:
// this gives you the full url
$request_uri = $_SERVER['REQUEST_URI'];
// split the path by '/'
$params = split("/", $request_uri);
然后您可以基于这些$params进行路由。
作为一个好的快速路由器库,我建议:
通过使用它,您不必乱搞htaccess regexp的东西,并且可以将东西保持在PHP级别:)