Reputation: 140
So I have a RewriteCond that turns:
domain.com/view.php?a=1
into:
domain.com/artist/name
I have a shorter domain: dmn.com
that I would like to provide shortlinks for artists:
dmn.com/name
How can I get dmn.com/name
to redirect to: domain.com/artist/name
while keeping the shortlink in tact?
.htaccess:
#rewrite profile requests
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule artist/(.*)$ view.php?a=$1 [QSA,NC,L]
httpd.conf:
<VirtualHost *:80>
DocumentRoot /var/www/html/ // <-- ??? not sure what to put here
ServerName dmn.com
ServerAlias www.dmn.com
</VirtualHost>
Since the directory "/artist" doesn't actually exist (since it's being rewritten), I can't seem to put /var/www/html/artist
in the DocumentRoot of the VirtualHost config without Apache spitting back:
Warning: DocumentRoot [/var/www/html/artist] does not exist
Upvotes: 0
Views: 1188
Reputation: 8181
I think what you want is not an actual redirection, but another rewrite.
You can't do it with a separate VirtualHost
. Well, you can if you point it to the same DocumentRoot
and duplicate your rules or load them from a common file, either via .htaccess
or a Include
directive.
You can also add the short domain name to your main domain ServerAlias
<VirtualHost *:80>
# This should point to your current config
DocumentRoot /var/www/artists_profiles/
ServerName example.com
ServerAlias www.example.com ex.com www.ex.com
</VirtualHost>
Then you add the new rules to the top of the file:
RewriteBase /
RewriteCond %{HTTP_HOST} ex.com
RewriteRule ^(^.*) artist/$1
Then your existing rules should pick up. If you want to avoid the shortened domain from responding to the longer urls you could add a similar RewriteCond
to the existing rules:
RewriteCond %{HTTP_HOST} !ex.com
Upvotes: 1