Mod-rewrite for GET parameter on subdomains

I am trying to rewrite the subdomain (NOT REDIRECT) into the $ _ GET parameter as such:

Desired Result:

http://go.example.bz/link/abcde -> http://example.bz/go/link?id=abcde or http://go.example.bz/hrm/employee/8 -> http://example.bz/go/hrm/employee?id=8 

What is currently working:

 http://example.bz/go/link/abcde -> http://example.bz/go/link?id=abcde and http://example.bz/go/hrm/employee/8 -> http://example.bz/go/hrm/employee?id=8 

with this .htaccess in the root:

 RewriteEngine On RewriteRule ^go/link.php/([^/\.]+)/?$ go/link.php?id=$1 [L] RewriteRule ^go/hrm/employee.php/([^/\.]+)/?$ go/hrm/employee.php?parameter=$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [NC,L] AddCharset UTF-8 .php Options -Indexes 

and that’s how I redirect the subdomain:

 <VirtualHost *:80> Servername go.example.bz DocumentRoot /var/www/go </VirtualHost> 

I don't want to redirect to destination β†’ to save the http://go.example.bz/link/abcde url, but the results / links? Abcde

+6
source share
4 answers

I realized that my problem arose because the .php extension was not removed from the subdomain URLs from which I found the answer here https://css-tricks.com/forums/topic/remove-php-extension- from-subdomain-urls / , and then I alternated my RewriteRules as such:

 RewriteEngine On RewriteRule ^go/link/([^/\.]+)/?$ go/link.php?id=$1 [L] RewriteRule ^go/hrm/employee/([^/\.]+)/?$ go/hrm/employee.php?id=$1 [L] RewriteEngine on RewriteCond %{HTTP_HOST} ^go\.example\.bz$ [OR] RewriteCond %{HTTP_HOST} ^www\.go\.example\.bz$ RewriteRule ^/?$ "http\:\/\/tgc\.bz\/go" [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^([^\.]+)/$ $1.php AddCharset UTF-8 .php Options -Indexes 
+2
source

This rule can be used in the root directory .htaccess:

 RewriteEngine On RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.(example\.com)$ [NC] RewriteRule ^(link)/(.+)$ http://%2/%1/$1?id=$2 [NC,L,QSA,R=302] 
+1
source
 RewriteEngine On RewriteCond %{HTTP_HOST} ^go.example.com RewriteRule ^(.*?)/(.*)$ http://example.com/go/$1?id=$2 [L] 
0
source

Does it help:

 RewriteCond %{HTTP_HOST} ^go.example.com$ RewriteRule ^link/([a-zA-Z0-9]+)$ http://example.com/go/link?id=$1 [P] 
0
source

All Articles