.htaccess wildcard subdomain pointing to directory + hash

1

Pretty simple to doubt. Redirect by .htaccess containing a subdomain wildcard and hash.

From:

http://carros.domain.com/visualizar#123
http://casas.domain.com/visualizar#345
http://aps.domain.com/visualizar#567

To:

http://domain.com/carros/ver#123
http://domain.com/casas/ver#345
http://domain.com/aps/ver#567

My biggest problem is to change the "view" to the "see". I tried many ways and failed the mission.

Something approximate that I found here in the stack:

 RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com/visualizar
 RewriteRule ^(.*)$ http://domain.com/%1/ver/$1 [L,NC,QSA]

EDIT:

Solution that worked based on the responses of these beautiful people:

   RewriteCond %{HTTP_HOST} carros\.domain\.com
   RewriteCond %{REQUEST_URI} visualizar([^#]+)?([#\d\w\s]+)?
   RewriteRule (.*) http://domain.com/ver%1%2 [R=301,L]

I repeated this for all my subdomains.

    
asked by anonymous 11.12.2015 / 07:31

2 answers

1

This rule redirects all subdomains:

   RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.foo\.bar$
    RewriteRule ^/?(.*)$ http://www.foo.bar/$1 [R=301,L]

Based on this, your case would look like this

   RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.foo\.bar/visualizar$
    RewriteRule ^/?(.*)$ http://www.foo.bar/carros/ver$1 [R=301,L]
    
11.12.2015 / 09:48
1

Using the possibility of regex having numbered capture groups I think this might work:

RewriteEngine on
RewriteRule ^https?:\/\/([^\.]+)\.domain\.com\/([^#]+)([#\d]+)$ http://domain.com/$1/ver$3 [R=301,L]

Based on regex behavior like this: link , the idea is to capture 3 groups and regroup 2 of them in rewrite

    
11.12.2015 / 17:23