Rewriting a number based URL using .htaccess Rewri

2019-06-18 04:36发布

问题:

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