Jump to content

remove /1 from url and redirect there


ram4nd

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/233956-remove-1-from-url-and-redirect-there/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.