1 Replies - 1268 Views - Last Post: 17 July 2013 - 12:15 PM Rate Topic: -----

#1 mshadow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 03-July 12

url rewriting in php on xampp server

Posted 17 July 2013 - 09:34 AM

I've trying out url rewriting with a php script on my xampp server. First i created a .htaccess on the same folder as the script and then wrote the following lines in it
RewriteEngine On # Turn on the rewriting engine 
RewriteRule ^direct/?$ direct_name_here.php [NC,L]

to rewrite localhost/map/direct_here123.php to localhost/map/direct/

But the browser displays the url localhost/map/direct_here123.php instead of localhost/map/direct/

How can i fix it?


Is This A Good Question/Topic? 0
  • +

Replies To: url rewriting in php on xampp server

#2 Atli  Icon User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4240
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: url rewriting in php on xampp server

Posted 17 July 2013 - 12:15 PM

The mod_rewrite module doesn't rewrite the URLs shown in the browser. It rewrites how Apache follows URL paths internally.

The rewrite rule you posted will map the URL "direct/" so that it will load the "direct_name_here.php" file instead. - So if you were to write example.com/direct/ into your browser, the Apache server would return the contents of the example.com/direct_name_here.php file. But it won't change the URL displayed in the browser at all.

If you want to change what URL the user sees, you need to do an actual redirect; instruct the browser to go to a new URL. For example:
RewriteRule ^old_name_here.php$ new_name_here [L,R=301]

This will make it so that if you use the name of the old file in the browser address bar, Apache will send a 301 redirect and point it to the new file instead. The browsers will then redirect the user to the new URL, changing the value in the address bar in the process.

Note: A 301 redirect tells the browser the file has moved permanently. If you want it to be temporary, use 302 instead.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1