How to redirect user to the same when trying to modify url end?

Hi,
I am a php newbie and would like to expose a situation about url i remarked on some website. On some website, it is like they have a default url when a link does not exist…example this is link for creating customer account

[php]www.koukou.com/customer/create/[/php]

I have tried to change their url to this:

[php]www.koukou.com/customer/create/naruto[/php]

instead of mentioning that the error message

T[php]he requested URL /koukou/compte/naruto was not found on this server.[/php]

it is just redirect me back to[php] the login form[/php] of [php]www.koukou.com/customer/create/[/php] .

So, how can i redirect user to page when the requested url does not exist in my server?

Hope i have exposed my issue clearly…thanks in advance

You are looking for a custom error message. These are handled through your hosting account generally.

Most likely you might be looking for a URL rewrite. That is done on the server. It allows you to do several
different things on your URL’s for your site.

As an example for your post, you said that it had /customer/create/name …

But, most likely BEHIND the scenes, it really said something like /customer?add_new_name=“blahblah”
And, that translated to /customer/create/blahlblah…

This is a trick that a lot of sites use to hid the parms they send to scripts. It makes it more readable and
easier to pass on to others in an email or over the phone. I have seen it a lot on sites. Although I only
used this on one site that never became public…

Well, here is a link for a tutorial that explains it somewhat. Hope it helps!
https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

You can do this rather easily

if using apache, add this to your vhost file (or in a .htaccess file in your project root):

<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ / [L,QSA] </IfModule>

in nginx you add this to your vhost file:

location / { try_files $uri $uri/ /index.php; }

This will redirect all hits that don’t go to an existing file to the front page (/)

[hr]

Another solution which is being done by most frameworks today is to have a router in your app. So you set the web server to redirect all traffic (existing and non existing files/folders) to index.php, and your router takes care of which code to load. If the router tries to load a route you haven’t set up, it will redirect to a 404, the front page, or wherever you like.

Sponsor our Newsletter | Privacy Policy | Terms of Service