Apache 重写规则匹配和覆盖
Apache Rewrite rule matches and overwriting
我对正则表达式真的很陌生,我很难修复我的重写规则。
当前结构是这样的:
RewriteEngine on
RewriteRule ^data.js$ /data.php [NC,L]
RewriteRule ^api/(.*)$ /api.php [NC,L]
RewriteRule ^(profile|photo)/?(.*)$ /index.php [NC]
如果我只寻找 /profile
或 /photo
视图,一切正常。但是我想自动允许 /messages
或 /settings
,例如因为每次添加新的 view
时,htaccess 也需要对那些 alternative literals
进行修改。现在,我的问题是如何替换 matching group
以允许任何 link 像这样:
/
/segment
/segment/?(.*)
我尝试允许一切,但我最终得到 "Internal Server Error":
RewriteRule .* /index.php
也试过^(.*)$
和其他选项..也试过这个:
RewriteRule ^([A-Za-z0-9\.])/?(.*)$ /index.php
为了允许任何字母数字单词,但我仍然以 "Internal Server Error" 结束,我知道我用 match any of content
弄乱了方括号 .. 有人可以启发我吗?
您可以使用:
RewriteEngine on
RewriteBase /
RewriteRule ^data\.js$ data.php [NC,L]
RewriteRule ^api/(.*)$ api.php [NC,L]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
我对正则表达式真的很陌生,我很难修复我的重写规则。
当前结构是这样的:
RewriteEngine on
RewriteRule ^data.js$ /data.php [NC,L]
RewriteRule ^api/(.*)$ /api.php [NC,L]
RewriteRule ^(profile|photo)/?(.*)$ /index.php [NC]
如果我只寻找 /profile
或 /photo
视图,一切正常。但是我想自动允许 /messages
或 /settings
,例如因为每次添加新的 view
时,htaccess 也需要对那些 alternative literals
进行修改。现在,我的问题是如何替换 matching group
以允许任何 link 像这样:
/
/segment
/segment/?(.*)
我尝试允许一切,但我最终得到 "Internal Server Error":
RewriteRule .* /index.php
也试过^(.*)$
和其他选项..也试过这个:
RewriteRule ^([A-Za-z0-9\.])/?(.*)$ /index.php
为了允许任何字母数字单词,但我仍然以 "Internal Server Error" 结束,我知道我用 match any of content
弄乱了方括号 .. 有人可以启发我吗?
您可以使用:
RewriteEngine on
RewriteBase /
RewriteRule ^data\.js$ data.php [NC,L]
RewriteRule ^api/(.*)$ api.php [NC,L]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]