I have a problem with redirecting the wild-card subdomain and shortening the internal URL.
Say I have an internal URL in my application
example.com/b/ABCDE
which will translate
example.com/book/12345678-the-book-name
The script referenced /b/(I use the PHP framework that can handle the URL rule) will translate the short identifier ABCDEinto the real identifier of the book 12345678(and the title "Book Name"), and then redirect this to the permanent URL of the bookexample.com/book/12345678-the-book-name
so every time I distribute a link to a book on sites such as message boards, micro-blog sites, or physical media like posters or business cards, I use a short link ( example.com/b/ABCDE) instead of a permanent link ( example.com/book/12345678-the-book-name).
next, I need to redirect all wild-card subdomains to the main domain ( www.example.com) while saving the request URI, for example.
http://random.example.com/book/11111111-some-book -> http://www.example.com/book/11111111-some-book
http://123456.example.com/book/22222222-another-book -> http://www.example.com/book/22222222-another-book
http://abcdefg.example.com/book/33333333-another-book-again -> http://www.example.com/book/33333333-another-book-again
adding the rule below after all the rules that I used
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301]
</VirtualHost>
Therefore, a url with the domain example.com and without a prefix, as shown below
http:
will switch to
http:
And another consequence is that if the internal URL shortener uses a simple domain without a prefix, two redirects will be required to eliminate it. For instance,
http:
will be redirected to
http:
which is then redirected to
http:
, . SEO , . ( )
,
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{REQUEST_URI} ^/b/(.*)$
RewriteRule . index.php [L]
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^/(.*)$ http://www.example.com/$1 [R=301]
</VirtualHost>
Apache, http://htaccess.madewithlove.be/, . , 400 Bad Request example.com/p/ABCDE.
, :
- SEO ? - , -?
- 400 Bad Request?
- ? URL (
example.com/b/ABCDE www), .