Setting a default Apache RewriteRule entry

2019-06-03 17:43发布

I want to set a 'default' rewrite rule to catch anything that didn't match the previous rewrite entries. I've tried this:

RewriteRule ^(.*)/?$ index.php?url=$1 [L]

But the output returned is:

url = index.php

Ideally what I want is to attach all the GET values to 'url' so they will be saved to my web log. Anyone have any suggestions how to solve this?

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-06-03 18:15

You need to exclude the destination from your rule:

RewriteCond $1 !=index.php
RewriteRule ^(.*)/?$ index.php?url=$1 [L]
查看更多
放荡不羁爱自由
3楼-- · 2019-06-03 18:22

Omit needless parentheses in regular expressions whenever you can:

RewriteRule .* index.php?url=$0 [L]

If you want to exclude "index.php":

RewriteRule ^(?!index\.php).* index.php?url=$0 [L]
查看更多
老娘就宠你
4楼-- · 2019-06-03 18:35

Try to remove slash:

RewriteRule ^(.*)$ index.php?url=$1 [L]
查看更多
登录 后发表回答