开发者

Problem in redirection through .htaccess

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

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

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.

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)

开发者_JAVA技巧

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"...

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?


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]


forget about .htaccess it's easier to do it in php,i use it in my site, i created an index.php file to redirect users from example.com to example.com/123

in my index.php i put this

<?php
header('Location: http://example.com/123');
?
>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜