简体   繁体   English

在末尾用/清除php中的url

[英]Clean urls in php with / at the end

I am trying to figure those clean urls out again. 我试图再次找出那些干净的网址。 I am trying to "convert" 我正在尝试“转换”

http://www.website.com/videos.php?url=testurl http://www.website.com/videos.php?url=testurl

into

http://www.website.com/videos/testurl/ http://www.website.com/videos/testurl/

All of that works fine as long as I write the url without the / at the end. 只要我写的URL末尾没有/,所有这些都可以正常工作。 But for me it is really important to have the / at the end. 但是对我来说,在末尾加上/非常重要。

Here is my htaccess: 这是我的htaccess:

RewriteBase /
RewriteRule ^(.*)\/$ $1.php
RewriteRule videos/(.*)/?$ /videos.php?url=$1

Any help would be appreciated. 任何帮助,将不胜感激。

Have it this way: 有这种方式:

Options -MultiViews
RewriteEngine On
RewriteBase /

RewriteRule ^videos/([^/]+)/?$ videos.php?url=$1 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

What you're looking for is rtrim : 您正在寻找的是rtrim

$url = 'http://www.website.com/videos/testurl/';
$url = rtrim($url, '/');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM