1

Its like My current url address is

http://localhost/foldername/index.php

and i wanna show this as http://localhost/foldername is it possible with jquery/JS without using .htaccess

anubhava
790k67 gold badges603 silver badges671 bronze badges
asked Sep 22, 2013 at 9:17

2 Answers 2

1

A simple Javascript will be sufficient for this:

if ((n=location.href.indexOf("/index.php")) > -1)
 location.assign(location.href.substring(0, n));
answered Sep 22, 2013 at 9:23
Sign up to request clarification or add additional context in comments.

Comments

0

There are two parts to making a pretty URL:

  1. if you load the "ugly" URL, redirect to the "pretty" URL
  2. if you load the "pretty" URL, serve the right content

JS can help with (1), because it can see the current URL, and send the browser somewhere else.

For (2), though, you need something on the server-side, because when the browser requests http://localhost/categoryname, the server needs to know what to send it.

This is what mod_rewrite is for. Note that .htaccess is just a file you can put Apache configuration in, not the name of the configuration itself; it's commonly used on shared hosts where you don't have access to the core Apache config.

mod_rewrite can be complicated, but it doesn't need to be. Don't be scared, and don't try to find an exotic workaround which will end up more complicated than modifying a few examples of RewriteRule found online. :)

answered Sep 22, 2013 at 12:17

3 Comments

now i know its impossible without .htaccess may i know how .htaccess do that? im newbie and dont know how to do that
Just look around online for basically any introduction to mod_rewrite. This is about as simple as rules get.
hmm thnx a lot for yr help

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.