开发者

.htaccess redirection

开发者 https://www.devze.com 2022-12-14 10:39 出处:网络
Hello I want to have some redirection ma开发者_如何学Gode by .htaccess file: Some examples mysite.com/accepted -> mysite.com/index.php?type=accepted

Hello I want to have some redirection ma开发者_如何学Gode by .htaccess file: Some examples

mysite.com/accepted -> mysite.com/index.php?type=accepted
mysite.com/waiting -> mysite.com/index.php?type=waiting
mysite.com/cancelled -> mysite.com/index.php?type=cancelled

&

mysite.com/edit/2 - > mysite.com/admin.php?edit=2

ETC. for all numbers possible

mysite.com/login -> mysite.com/admin.php?action=login
mysite.com/register -> mysite.com/admin.php?action=register
mysite.com/lostpassword - > mysite.com/admin.php?action=lostpassword 
mysite.com/add - > mysite.com/add.php

Apprectiate your help ;)

@edit: It should be done that way but with masking urls.


Which way around is the redirect? It would be common to see redirects from your given right-hand-sides to the left-hand-sides, but not the other way around.

EDIT I see you've fixed that, so my supposition was correct:

i.e. you'd normally see:

RewriteRule ^edit/([0-9]+)$ /admin.php?edit=$1 [L]

etc, to map the nice friendly RESTful style URL into the internal URL.


If you want to get into the topic yourself, www.modrewrite.com hosts a number of great mod_rewrite resources with lots of examples.


If I understand your edit correctly you want this

<?php
header('Location: http://mysite.com/'.$_GET['type']);
?>


Since there is no structural pattern in your URLs that can be used to map the URLs to the destinations, you probably will need to use one rule for each group like these:

RewriteRule ^add$ add.php [L]
RewriteRule ^(login|register|lostpassword)$ admin.php?action=$1 [L]
RewriteRule ^edit/(\d+)$ admin.php?edit=$1 [L]
RewriteRule ^(accept|waiting|canceled)$ index.php?type=$1 [L]


Maybe something like the following?

RewriteRule ^www.domain.com/([^/]+)/([^/]+)/([^/]+)/([^/]+) /index.php?$1=$2&$3=$4 [NC]

Do note that you will have to parse the URL (REQUEST_URI) instead of accessing $_GET

0

精彩评论

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

关注公众号