apache 使用 .htaccess RewriteRule 重写基于数字的 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2460044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rewriting a number based URL using .htaccess RewriteRule
提问by Alex
How can I rewrite a simple number based URL to a sub folder?
如何将一个简单的基于数字的 URL 重写到子文件夹?
I want http://mysite.com/123to redirect to http://mysite.com/en/123.
我希望http://mysite.com/123重定向到http://mysite.com/en/123。
The number could be anything from 1 - 9999. My attempt in htaccess was:
数字可以是 1 - 9999 之间的任何值。我在 htaccess 中的尝试是:
RewriteRule ^([0-9]+)$ /en// [R]
But that doesn't work.
但这不起作用。
采纳答案by Joko Wandiro
your syntax is right, I just remove slash in the end of line and it works:
你的语法是正确的,我只是删除了行尾的斜杠,它可以工作:
RewriteRule ^([0-9]+)$ /en/
回答by Aron
Make sure that this 3 lines are writen in your HtAccess File (sorry for mybad english)
确保这 3 行写在你的 HtAccess 文件中(抱歉我的英语不好)
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
##
## Now the rewrite
RewriteRule ^([0-9]+)$ ./en/

