0

I am trying to get a pretty permalink system set up on a site I've just built and nothing is having any effect. I either get a 500 error or the permalinks don't work and/or it breaks all the links to CSS and images while still giving a 404 if you try to use the permalink structure.

Here is my .htaccess code:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /main/index.php?act=$1&sub=$2&id=$3 [L]

I want it to convert links like index.php?act=admin&sub=edit-product&id=5 to /admin/edit-product/5 whilst including any in between. For example, if a URL has an ID call but not a sub call it will still work.

Any help would be greatly appreciated.

UPDATE:

I have added RewriteBase / and it has now doing something, but the permalinks are not working properly.

Is there a way I can find out where the rewritten URL is actually pointing?

It seems that full URLs that use all the rewrite rules work, but not the URLs that only need some of them.

4

1 回答 1

1

我在我的项目中使用这个 .htaccess 代码进行重写:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

此代码传递按原样存在请求(用于静态文件等),但所有其他重定向到 index.php。请求 uri 可用 int PHP 作为

$_REQUEST['REQUEST_URI']

在 PHP 中,我们(或我们的框架)可以随意解析它。

于 2013-05-07T16:59:47.633 回答