5

Could someone point me in the right direction? I'm trying to create a url like the one below. I don't want to use url hashes #I2QT40oSwU0AoH7g02cAHI or parameters ?myparam=I2QT40oSwU0AoH7g02cAHI.

https://www.dropbox.com/l/I2QT40oSwU0AoH7g02cAHI

Is this done with mod_rewrite?

Many thanks!

DeFeNdog
  • 1,156
  • 1
  • 12
  • 25

3 Answers3

2

Yes, it's done by editing the httpd.conf file (turn on AllowOverride all) and creating a .htaccess file in your root web directory.

Here is a sample .htaccess file

Options -Multiviews

RewriteEngine On
RewriteBase /

RewriteRule ^l/(.*)$ /somescript.php?key=$1 [L]

The above will direct

https://www.dropbox.com/l/I2QT40oSwU0AoH7g02cAHI

to

https://www.dropbox.com/somescript.php?key=I2QT40oSwU0AoH7g02cAHI
Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248
  • I would not turn on "AllowOverride all" globally in httpd.conf. You have to understand what you're doing. It's security feature. Read [here](http://stackoverflow.com/questions/18740419/how-to-set-allowoverride-all) – Eduard Jan 19 '14 at 07:07
  • @eduard It's a security feature that protects malicious evil doings if an attacker gets access to your .htaccess file. If you don't turn it on, then you can't rewrite URLs through Apache. If you do turn it on, and an attacker gains access to your root directory (hence the .htaccess file), well then you have much bigger things to worry about than URLs being redirected wonkly – Lloyd Banks Jan 19 '14 at 08:07
1

It's called Clean URL Usually it's implemented via url rewrite technique. But also you can use 404 HTTP error page to handle such urls.

Eduard
  • 1,464
  • 15
  • 19
1

Yes it is! A mod rewrite is exactly what you are looking for. You can play around with this generator here: http://www.generateit.net/mod-rewrite/index.php

Here is the solution:

Put a .htaccess in your root, add this to it. When the user enters

http://domain.com/l/I2QT40oSwU0AoH7g02cAHI

it will execute this "hidden" on the server

http://domain.com/index.php?myparam=I2QT40oSwU0AoH7g02cAHI

Add this:

RewriteEngine On

# /l/ trick
RewriteRule ^l/([^/]*)$ /index.php?myparam=$1 [L]
Satbir Kira
  • 792
  • 6
  • 21