我有一个PHP生成的文件,如: www.domain/?mod=test&act=view
I have a php generated file like: www.domain/?mod=test&act=view
和我想创建从该地址重定向到这样的: www.domain/view-test
And I want to create a redirection from that address to something like: www.domain/view-test
,这样每次用户(或机器人)进入第一个URI它被重定向到 HTTP:// WWW .domain /视图测试观看第一个URI的内容。
so that everytime a user (or bot) accesses the first uri it gets redirected to www.domain/view-test viewing the content of the first uri.
现在,我有我的.htaccess根据以下规则:
Right now I have the following rules under my .htaccess:
RewriteRule ^view-test$ /?mod=test&act=view [NC] RewriteCond %{QUERY_STRING} mod=test&act=view RewriteRule ^(.*)$ /view-test? [R,L]第一条规则创造了一个别名页如果我删除其他两条线工作(但我想不会重定向我的用户)
The first rule creates a "page alias" and works if I delete the other two lines (but doesn't redirect my users as i want to)
将最后两个规则,我在一个循环或某事结束了,我也得到一个broswer消息说该网页无法正确重定向后...
After placing the last two rules I end up in a Loop or something and I get a broswer message saying "The page is not redirecting correctly"...
如果我删除第一条规则,我得到一个404错误说/视图测试找不到
If I remove the first rule I get an 404 error saying /view-test could not be found
任何想法,我做错了什么?
Any idea what I'm doing wrong?
推荐答案我认为,正则表达式是更好的。针对这种情况完全的.htaccess 文件,如果你的php处理程序的index.php
I think that regex is better. Full .htaccess file for this situation if your php handler is index.php
RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} mod=(\w+)&act=(\w+) RewriteRule ^$ /%2-%1? [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(\w+)-(\w+)$ /index.php?mod=$2&act=$1 [L]更多推荐
问题通过的.htaccess重定向
发布评论