Mobile app version of vmapp.org
Login or Join
Margaret670

: Issue with permanent redirect implementation I have a tricky problem related to 301 redirections I badly need help with. I tried to implement these via .htaccess, but ran into trouble. The start

@Margaret670

Posted in: #301Redirect #Apache #Htaccess #ModRewrite

I have a tricky problem related to 301 redirections I badly need help with.
I tried to implement these via .htaccess, but ran into trouble.

The start of my .htaccess looks like this:

SetEnv PHP_VER 5
Options +FollowSymlinks
RewriteEngine on

# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^(www.|$) [NC]
RewriteRule ^ www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#--- GENERAL ---
RewriteRule ^index.html$ index.php [L]
...


When I try to put a permanent redirect to index.php by adding R=301 in the square brackets,
I get a 404, and I have no idea where the error comes from.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Margaret670

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

To force to be present in a domain name try this one instead (it's safer to have domain name hard coded):

RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule (.*) www.example.com/ [QSA,R=301,L]


A bit different version (with no domain name hard coded):

RewriteCond %{HTTP_HOST} !^www.(.*)$
RewriteRule (.*) www.%{HTTP_HOST}/ [QSA,R=301,L]


But if your configuration allows to to also accept requests for domain like meow.example.com .. then it will be redirected to meow.example.com.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme