让PHP读取由.htacces创建的干净URL

让PHP读取由.htacces创建的干净URL,php,Php,我正在尝试创建干净的URL,到目前为止,我已设法使用.htaccess转换以下URL: www.example.com/index.php?catagory=Section1&page=Page1 进入: www.example.com/Section1/Page1/ 问题是让PHP解释URL并提取变量。以下是我使用的代码: .htaccess代码: Options +FollowSymLinks Options +Indexes RewriteEngine on INTERNAL STATI

我正在尝试创建干净的URL,到目前为止,我已设法使用.htaccess转换以下URL:

www.example.com/index.php?catagory=Section1&page=Page1

进入:

www.example.com/Section1/Page1/

问题是让PHP解释URL并提取变量。以下是我使用的代码:

.htaccess代码:

Options +FollowSymLinks
Options +Indexes
RewriteEngine on

INTERNAL STATIC URL TO DYNAMIC URL
RewriteRule ^/([^/]+)/?$ /index.php?c=$1 [L]
RewriteRule ^/([^/]+)/([^/]+)/?$ /index.php?c=$1&p=$2 [L]

EXTERNAL DYNAMIC URL TO STATIC URL
RewriteCond %{THE_REQUEST} ^[a-zA-Z0-9]{1,3}\ /index\.php\?catagory=([^&]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%1/? [R=301,L] 
RewriteCond %{THE_REQUEST} ^[a-zA-Z0-9]{1,3}\ /index\.php\?catagroy=([^&]+)&page=([^&]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%1/%2/? [R=301,L] 
PHP代码:

$urlVariables = explode("/",$_SERVER['REQUEST_URI']);
$catagory = $urlVariables[1];
$page = $urlVariables[2];
有了这个,我一直得到一个404错误页面。如果我将index.php添加到这行htacces代码中:

RewriteRule ^index\.php$ http://www.example.com/index.php/%1/? [R=301,L]

页面至少会加载,但不会加载css和图像。

在.htaccess文件中使用mod_rewrite时,需要从模式中删除上下文本地路径前缀。因此,对于根目录中的.htaccess文件,前导的
/

RewriteRule ^([^/]+)/?$ /index.php?c=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?c=$1&p=$2 [L]

在.htaccess文件中使用mod_rewrite时,需要从模式中删除上下文本地路径前缀。因此,对于根目录中的.htaccess文件,前导的
/

RewriteRule ^([^/]+)/?$ /index.php?c=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?c=$1&p=$2 [L]