Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewriting a number based URL using .htaccess RewriteRule

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.

like image 207
Alex Avatar asked Mar 17 '10 05:03

Alex


People also ask

How can I redirect and rewrite my URLs with an .htaccess file?

Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.

What is RewriteRule in htaccess?

htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.

What is RewriteCond and RewriteRule?

There are two main directive of this module: RewriteCond & RewriteRule . RewriteRule is used to rewrite the url as the name signifies if all the conditions defined in RewriteCond are matching. One or more RewriteCond can precede a RewriteRule directive.


2 Answers

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

RewriteRule ^([0-9]+)$ /en/$1
like image 123
Joko Wandiro Avatar answered Sep 16 '22 18:09

Joko Wandiro


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
like image 36
Aron Avatar answered Sep 18 '22 18:09

Aron