Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top