htaccess的得到code和重定向用PHP [英] htaccess get code and redirect with php

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

问题描述

例如:

如果我们进入这些URL(喜欢这个网站)

If we entered these url (Like This site)

http://stackoverflow.com/questions/10139779/ http://stackoverflow.com/questions/10139779

它的自动重定向到这个网址 http://stackoverflow.com/questions/10139779/handling-get-with-htaccess

Its automatically redirect to this url http://stackoverflow.com/questions/10139779/handling-get-with-htaccess

我想获得这个code (10139779)网​​址,然后重定向到完整的URL。有人去完整的URL如何得到这个code (10139779)

I want to get this code (10139779) from url and redirect to full url. Someone go to full url how to get this code (10139779)

编辑:

我创造了这样的htaccess文件。

I created htaccess file like this.

<Files .htaccess>
order allow,deny
</Files>

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^(\w+)$ ./load.php?code=$1

现在我想给视频标题视频ID喜欢这个后,网址 www.example.com/16056/video-title

Now i want to give video title to url after video id Like this www.example.com/16056/video-title

load.php

<?php
echo $_GET['code'];

//I can get video title from php then how to give to url it?
?>

我可以得到$ C C本$从 www.example.com/16566 ,但我不能得到code这个从这个网址 www.example.com/16566/video-title

I can get code this from www.example.com/16566 but i can't get code this from this url www.example.com/16566/video-title

在ID / 链接是行不通的。如何修复它

after id / link was doesnt work. how to fixed it

推荐答案

发送了位置标头为正确的网址。 ( load.php 的:)

Send out a location header for the correct URL. (load.php:)

<?php
    header('Location: /videos/'.$_GET['code'].'/'.getTheVideoTitle($_GET['code']));
?>

还有,你可以在.htaccess获得视频标题做什么,所以PHP必须这样做。

There is nothing you can do in .htaccess to get the video title, so php must do it.

此外,为的.htaccess:

Also, for .htaccess:

RewriteRule ^(\w+)$ ./load.php?code=$1

应该是:

RewriteRule ^(\w+)/*$ ./load.php?code=$1

这使得它在URL后匹配斜线(S)。如果你也希望它在URL后匹配的称号,使之:

This makes it match slash(s) after the URL. If you also want it to match the title after the URL, make it:

RewriteRule ^(\w+) ./load.php?code=$1

这篇关于htaccess的得到code和重定向用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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