Loka
Loka

Reputation: 13

How can I rewrite this URL with Apache?

I want to be able to access sitenamehere.com/folder/index?a=something by visiting sitenamehere.com/folder/something in my address bar.

How can I do this?

I've looked into mod rewrite but I don't understand it.

Upvotes: 1

Views: 96

Answers (2)

Ian Wetherbee
Ian Wetherbee

Reputation: 6109

mod_rewrite is an Apache (web server) extension not related to PHP. You'll want to create a file called .htaccess and include the following line:

RewriteEngine On
RewriteRule ^folder/(.*) /folder/index.php?a=$1

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

Upvotes: 3

alex
alex

Reputation: 490283

Your .htaccess or httpd.conf.

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Your rule
RewriteRule ^([^/]+)/([^/]+)/?$ $1/index?a=$2 [L]

This assumes you want where folder is to be mapped over to where folder is in your example. If you want to match the literal folder, just replace the first capturing group with it (and add it to the replacement).

Upvotes: 2

Related Questions