Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

.htaccess - apache RewriteRule prefix with wwwwww instead of www

Using this for example:

RewriteEngine On  
Rewritecond %{HTTP_HOST} !^www.hslab.nl
RewriteRule (.*) http://www.hslab.nl/$1 [R=301,L]

It will add the www part to the url if it is not there. Why can it not be something other then www, for example wwwwwww? When I do that I get a 404.

question from:https://stackoverflow.com/questions/65883113/apache-rewriterule-prefix-with-wwwwww-instead-of-www

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs.

RewriteEngine ON
##Rule when www is present in URL so add only www to url.
Rewritecond %{HTTP_HOST} ^(www).hslab.nl
RewriteRule ^ http://%1%1.hslab.nl%{REQUEST_URI} [NE,R=301,L]

##Rule when www is NOT present in URL, hence add wwwwww to url as per OP
Rewritecond %{HTTP_HOST} !^www.hslab.nl
RewriteRule ^ http://wwwwww.hslab.nl%{REQUEST_URI} [NE,R=301,L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...