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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top