Stanisław Chmiela
Stanisław Chmiela

Reputation: 471

URL rewriting apache2

How would I be able to rewrite

anyhost.com/argument1/parameter2/some-text/

as

anyhost.com/index.php?path=argument1/parameter2/some-text/

or

anyhost.com/index.php?page=argument1&subpage=parameter2&subsubpage=some-text

or anything like that?

Upvotes: 2

Views: 148

Answers (2)

osoner
osoner

Reputation: 2415

RewriteRule (.*)?/ index.php?path=$1

This is for the first version.

RewriteRule (.*)/(.*)/(.*)?/ index.php?page=$1&subpage=$2&subsubpage=$3

This is for the second one. You can always test your rewrites using this tool.

Upvotes: 1

Clive
Clive

Reputation: 36957

This should do it:

RewriteEngine On

# First example
RewriteRule ^(.*)$ index.php?path=$1 [L,QSA]

# Second example
RewriteRule ^(.*)/(.*)/(.*)$ index.php?page=$1&subpage=$2&subsubpage=$3 [L,QSA]

The QSA flag is to auto-append any query string from the original URL to the query string sent to index.php; you can remove it if you don't need that functionality.

Upvotes: 1

Related Questions