简体   繁体   中英

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

into

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

All of that works fine as long as I write the url without the / at the end. But for me it is really important to have the / at the end.

Here is my 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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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