问题通过的.htaccess重定向 [英] Problem in redirection through .htaccess

查看:134
本文介绍了问题通过的.htaccess重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP生成的文件,如:
http://www.domain.com/?mod=test&act=view

I have a php generated file like: http://www.domain.com/?mod=test&act=view

和我想创建从该地址重定向到这样的:
http://www.domain.com/view-test

And I want to create a redirection from that address to something like: http://www.domain.com/view-test

,这样每次用户(或机器人)进入第一个URI它被重定向到 HTTP:// WWW .domain.com /视图测试观看第一个URI的内容。

so that everytime a user (or bot) accesses the first uri it gets redirected to http://www.domain.com/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重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆