我想使用modrewrite为我提供干净的网址:
http://www.mydomain.com/about/
是:
http://www.mydomain.com/index.php?page=about
进入三层。我写了这个,但它根本不起作用:
RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?section=$1&page=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?section=$1&subsection=$2&page=$3 [L]
我测试了添加print_r($ _ GET);当我去
时它是空的mydomain.com/about/
编辑,让它工作。愚蠢我不需要index.php之前的“/”。
然而,现在它不会告诉我我的css / images。我添加了这个,但它仍然没有用。
RewriteRule \.(css|jpe?g|gif|png)$ - [L]
它正在做的是将url参数附加到图像请求上:
/page/images/bg.jpg
而不是:
/images/bg.jpg
有什么想法吗?
答案 0 :(得分:1)
用以下内容替换现有内容:
# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
# don't do anything
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?section=$1&subsection=$2&page=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?section=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]