Brad Birdsall
Brad Birdsall

Reputation: 1743

Renaming PHP URLs with HTACCESS

I am building a web app that puts out a link like the following:

http://www.sample.com/?a=bj7phm

I would like for it to look something like this:

http://www.sample.com/BJ7PHM

Is this possible within the HTACCESS?

-B

Upvotes: 1

Views: 3239

Answers (2)

NiLL
NiLL

Reputation: 13843

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([0-9a-zA-Z+]{1,7})$?a=$1 [L]
</IfModule>

Upvotes: 0

Andrew Moore
Andrew Moore

Reputation: 95344

In order to do URL rewriting, you first need to:

  • Make sure you have mod_rewrite enabled on your server.
  • Make sure you have the proper permissions to add rules to your .htaccess file.
    (AllowOverride must be set to All or include FileInfo)

Then create the following .htaccess file in your web root:

RewriteEngine On
RewriteRule ^([\-_0-9A-Za-z]+)$  index.php?a=$1 [L]

You can customize RewriteRule as much as you want.

The first parameter is the regular expression to match the REQUEST_URI with (relative to the folder the .htaccess is in).

The second parameter is what you want to rewrite it to, $n being your match groups.

Upvotes: 1

Related Questions