问题通过的.htaccess重定向

编程入门 行业动态 更新时间:2024-10-27 20:32:32
本文介绍了问题通过的.htaccess重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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重定向

本文发布于:2023-10-31 19:23:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547045.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!