I\'m doing some url rewriting in PHP and need to find URLS with a slash at the end and then do a 301 redirect. I thought there\'d be a simple PHP function to find last stri
You can use basename()
This will return characters for http://domainx.com/characters/ as well as http://domainx.com/characters
You can do like this:-
$page = $_SERVER['REQUEST_URI'];
$module = basename($page);
Then you can use the $module directly in your conditional logic without doing any redirects.
If you want to collect the last / trimmed URL then you can do this:-
If you are storing the project base url in a config file:-
BASE_URL = 'http://example.com'
then you can do this:-
$page = $_SERVER['REQUEST_URI'];
$module = basename($page);
$trimmedUrl = BASE_URL.'/'.$module;