htaccess的得到code和重定向用PHP

编程入门 行业动态 更新时间:2024-10-25 00:28:56
本文介绍了htaccess的得到code和重定向用PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

例如:

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

If we entered these url (Like This site)

stackoverflow/questions/10139779/ 或 stackoverflow/questions/10139779

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

Its automatically redirect to this url stackoverflow/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/16056/video-title

Now i want to give video title to url after video id Like this www.example/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/16566 ,但我不能得到code这个从这个网址 www.example/16566/video-title

I can get code this from www.example/16566 but i can't get code this from this url www.example/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

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

发布评论

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

>www.elefans.com

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