Setting a default Apache RewriteRule entry

人盡茶涼 提交于 2019-12-08 04:57:12

问题


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?


回答1:


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]



回答2:


You need to exclude the destination from your rule:

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



回答3:


Try to remove slash:

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


来源:https://stackoverflow.com/questions/1855338/setting-a-default-apache-rewriterule-entry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!