Log in

View Full Version : Rewrite URL's



Valor Studios
06-29-2008, 05:59 PM
I'm looking for a quick way to remove .php extension from the URL and add a backslash at the end (also known as a trailing slash).

Example:
original url: www.domain.com/contact.php
rewritten ur: www.domain.com/contact/

I've been looking online for quite sometime now and cannot find a resource that adds a "/" at the end.

Additionally I was wondering if there is any way to keep the rewrite URL in only one directory. I dont want to have have a .htaccess file in every single directory with rewrite engine turned off.

hmsnacker123
07-15-2008, 12:23 AM
Do you mean when you go on: www.domain.com/contact.php it turns too: www.domain.com/contact/, because if you do in the contact.php file enter this:


<?php

header("Location: http://www.domain.com/contact/");

?>


Hope this helps :).

Nile
07-15-2008, 12:28 AM
No hmsnacker, he wants to know how to rewrite it.
Use mod_rewrite (http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html).

hmsnacker123
07-15-2008, 12:58 AM
I said:


Do you mean
And:


because if you do

Nile
07-15-2008, 01:30 AM
I was just saying.

magicyte
07-18-2008, 01:53 AM
That's PHP. JavaScript would be like this:


<script type="text/javascript">
function change_url()
{
var u = "http://www.domain.com/contact.php"; // Only 33 Characters - Start with ZERO - charAt() cannot exceed 32;

u.charAt(29) = " ";
u.charAt(30) = "";
u.charAt(31) = "";
u.charAt(32) = "";
u.charAt(29) = "/";

location.href = u;
}
</script>

That should do it. I didn't test it yet, but you are welcome to try it!

-magicyte