例如:
如果我们进入这些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
发布评论