Rewriting URLs with mod_rewrite to provide RESTful URLs

The web server is Apache. I want to rewrite the url so that the user does not know the actual directory. For example: Source URL:

www.mydomainname.com/en/piecework/piecework.php?piecework_id=11

Expected URL:

piecework.mydomainname.com/en/11

I added the following statements in .htaccess:

RewriteCond %{HTTP_HOST} ^(?!www)([^.]+)\.mydomainname\.com$ [NC]
RewriteRule ^(w+)/(\d+)$ /$1/%1/%1.php?%1_id=$2 [L]

Of course, I replaced mydomainname with my domain name. .htaccess is located at the root of the site, but when I access the piecework file .mydomainname.com / en / 11, I got "Object not found" (of course, I replaced mydomainname with my domain name.)

I added the following statements in .htaccess:

RewriteRule ^/(.*)/en/piecework/(.*)piecework_id=([0-9]+)(.*) piecework.mydomainname.com/en/$3

Of course, I replaced mydomainname with my domain name. .htaccess is located at the root of the site, but when I access the piecework file .mydomainname.com / en / 11, I got "Object not found" (of course, I replaced mydomainname with my domain name.)

What's wrong?

+3
source share
3

RewriteLog vhost server-conf, . , mod_rewrite.

RewriteLogLevel, . 5.

PS: / .

+2

. , , , , . , , URL-, URL-. , URL-, apache " "

, :

RewriteRule piecework.mydomainname.com/en/(*.) ^/$3/en/piecework/$3?piecework_id=([0-9]+)(.*)

, , , URL-, , Apache .

Update

, , . - , . :

RewriteRule www.mydomainname.com/en/piecework/piecework\.php\?piecework_id\=11 piecework.mydomainname.com/en/11

, , , .

0

, :

RewriteCond %{HTTP_HOST} ^(?!www)([^.]+)\.mydomainname\.com$ [NC]

-, .

$1 () , "www" 0 1 .

$2 , 1 , , , , -.

".mydomainname.com".

.

, , URL-:

RewriteCond %{HTTP_HOST} !^www\.mydomainname\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(\w+)\.mydomainname\.com$ [NC]
RewriteRule ^(\w+)/(\d+)$ /$1/%1/%1.php?%1_id=$2 [L]

, - , URL-, "www" ( ). , . .

.htaccess ...

-, , , - . , "\" "\ w" "\ d", .

0

Source: https://habr.com/ru/post/1737457/


All Articles