我不是.htaccess的专家。我想重写我的新闻和博客网址(有或没有www):
bdnews24.com/reporter.php?u=Name TO-> bdnews24.com/Name
m.bdnews24.com/reporter.php?u=Name TO-> m.bdnews24.com/Name
img.bdnews24.com/image.php?id=791011.jpg TO-> img.bdnews24.com/791011.jpg
bdnews24.com/details.php?id=100200300 TO-> bdnews24.com/100200300
我当前的.htaccess文件位于下方,无法正常工作。 这会捕获所有请求URI,如果不存在,它将转到index.php?u = ANYTHING
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# AlegroCart REWRITES START
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php/$1 [L,QSA]
答案 0 :(得分:1)
这套规则应该根据您提供的信息做您想做的事情:
RewriteCond {%QUERY_STRING} ^u=(.*)
RewriteCond %{HTTP_HOST} ^(m.|www.)?bdnews.com$
RewriteRule ^reporter.php /%1?
RewriteCond {%QUERY_STRING} ^id=(.*)
RewriteCond %{HTTP_HOST} ^img.bdnews.com$
RewriteRule ^image.php /%1?
RewriteCond {%QUERY_STRING} ^id=(.*)
RewriteCond %{HTTP_HOST} ^(m.|www.)?bdnews.com$
RewriteRule ^details.php /%1?
首先它匹配查询字符串,然后匹配主机名,然后将原始查询字符串(%1)重写为新URL。