Apache / mod_rewrite / Periods messing with pattern

冷暖自知 提交于 2020-01-05 08:05:11

问题


First question, here goes nothing...

I'm trying to add a new entry to my .htaccess file (Apache server) with the hopes of translating this URL:

http://platform.localhost/category.all

into this URL:

http://platform.localhost/index.php?page=category.all

The RewriteRule that I'm currently using is this:

RewriteRule ^([^/\.]+)\/?$ index.php?page=$1

This rule has worked fine for all URLs up until now, I can only assume that it is the period that is breaking it.

What I'm trying to achieve is having anything in the URL after the "http://platform.localhost/" passed into the "page" variable of index.php.

I know I've missed something stupid, can someone please be kind enough to point it out?

Cheers


回答1:


the pattern says to reject dots, but you could do tis:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]



回答2:


Why not just something like:

  RewriteRule index.php - [L]
  RewriteRule (.*) index.php?$1

This might fail because I don't remember exactly if querystrings are included when matching against the pattern, so I'm not sure what would result if you'd request:

http://bla.blub/x?q=1

Also note that this is for a .htaccess/directory context.



来源:https://stackoverflow.com/questions/2077304/apache-mod-rewrite-periods-messing-with-pattern

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