ram4nd Posted April 17, 2011 Share Posted April 17, 2011 I need permanent redirect. Example url: example.com/something/more/more/1 I always have /something/, so it would be awsome if you could remove /1 only from urls where are /something/ for first path argument. There can be any number of different url segments in between /something/ and /1, those should be kept there, just /1 should be removed. So the redirect path of the example url should be example.com/something/more/more How can I do this? Quote Link to comment https://forums.phpfreaks.com/topic/233956-remove-1-from-url-and-redirect-there/ Share on other sites More sharing options...
codebyren Posted April 17, 2011 Share Posted April 17, 2011 You could use the explode() function to break the url string into an array of segments (separated by '/'): <?php $url = "http://example.com/something/more/more/1"; $url_parts = explode('/', $url); ?> Then if 'something' is found as the first segment (looks like it would be in $url_parts[3] in my example), use php's substr() function to remove the '/1' from $url if relevant. Quote Link to comment https://forums.phpfreaks.com/topic/233956-remove-1-from-url-and-redirect-there/#findComment-1202552 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.