简体   繁体   English

使用正则表达式将URL替换为斜线

[英]Using regex to replace dot with slash in URL

I'm using a front controller which uses URLs as follows: 我正在使用一个使用URL的前端控制器,如下所示:

http://www.domain.com/index.php?action=main.Main , where 'main' is the module and 'Main' is the action. http://www.domain.com/index.php?action=main.Main ,其中'main'是模块,'Main'是动作。

For URL rewrite I use this line in the htaccess: 对于URL重写,我在htaccess中使用这一行:

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

This results in http://www.domain.com/main.Main.html 这会产生http://www.domain.com/main.Main.html

Now, how do I replace the dot between module and action with a slash so that the result looks like this: http://www.domain.com/main/Main ? 现在,如何使用斜杠替换模块和操作之间的点,以便结果如下所示: http//www.domain.com/main/Main

试试这个:

RewriteRule ^(.*)/(.*)$ index.php?action=$1.$2 [QSA]

Try this: 尝试这个:

RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)/(.*)\.html$ /$1.$2.html [L]

RewriteCond %{REQUEST_URI} \.html$
RewriteCond %{REQUEST_URI} !/.+/
RewriteRule ^([^/]+)\.html$ index.php?action=$1 [L,QSA] 

This will take a request like: http://www.domain.com/main/something/action/Main.html and rewrite the URI to: /index.php?action=main.something.action.Main 这将采取如下请求: http://www.domain.com/main/something/action/Main.htmlhttp://www.domain.com/main/something/action/Main.html并将URI重写为: /index.php?action=main.something.action.Main

RewriteRule ^(.*)/(.*)$ index.php?module=$1&action=$2 [QSA] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM