Rewriting a number based URL using .htaccess RewriteRule

﹥>﹥吖頭↗ 提交于 2019-12-23 08:50:03

问题


How can I rewrite a simple number based URL to a sub folder?

I want http://mysite.com/123 to redirect to http://mysite.com/en/123.

The number could be anything from 1 - 9999. My attempt in htaccess was:

RewriteRule ^([0-9]+)$ /en/$1/ [R]

But that doesn't work.


回答1:


your syntax is right, I just remove slash in the end of line and it works:

RewriteRule ^([0-9]+)$ /en/$1



回答2:


Make sure that this 3 lines are writen in your HtAccess File (sorry for mybad english)

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
##


## Now the rewrite
RewriteRule ^([0-9]+)$ ./en/$1


来源:https://stackoverflow.com/questions/2460044/rewriting-a-number-based-url-using-htaccess-rewriterule

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