0

I tried many many times, I read many examples but my .htaccess is not working. My domain is: liebeundsprueche.com/ When I go to www.liebeundsprueche.com/ it doesn't redirect me to liebeundsprueche.com/ Here is my .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ %{REQUEST_FILENAME} [L]
# invalid code - and useless if the ^ and % were joined

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index.php -f
RewriteRule ^ %{REQUEST_FILENAME}/index.php [L]
# invalid code as the second condition can NEVER happen and the Rule is flawed (regex of ^ !!!).
 RewriteCond %{HTTP_HOST} ^www\.liebeundsprueche\.com$
        RewriteRule ^/?$ "http\:\/\/liebeundspruechee\.com\/" [R=301,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule ^ 404/ [L]
# ditto
RewriteRule ^(.*[^/]) index.php?var=$1 [QSA,L]
</IfModule>

# END WordPress

Please let me know where is the error?

  • 1
    Does your server have mod_rewrite.c? Did you already contact your hoster? – kero Dec 11 '17 at 8:09
  • 1
    mod_rewrite is necessary if you want "pretty" URLs. As long as your .htaccess is valid, there is very little we can help here, most of it depends on your server, your domain configuration, etc – kero Dec 11 '17 at 8:18
  • 1
    But is htaccess file correct? what i typed.... if i crate sub domian with www. is it some? can it resolve problem? – vangogh94 Dec 11 '17 at 8:23
0

Try doing it via Cpanel (if you have access to it).

If not, clear ur HTACCESS with all the code you have written (except for default WordPress code) and add this.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.liebeundsprueche\.com [NC]
RewriteRule ^(.*)$ http://liebeundsprueche.com/$1 [L,R=301]
</IfModule>
  • I updated with your version but it soens't work. Please seeL: liebeundsprueche.com – vangogh94 Dec 11 '17 at 8:52
  • did you try the cpanel method? Is the www subdomain still active? – Sid Dec 11 '17 at 9:48
  • You can't use cPanel alone if you are using WordPress since cPanel always adds the directives at the end of the .htaccess file (after any WP front controller), so you would still need to modify .htaccess to rearrange the directives. This is discussed in the cPanel documentation regarding redirects. – MrWhite Dec 11 '17 at 12:02
0

You appear to have a server config issue (the DNS looks "OK"?), since the www subdomain doesn't even reach your site - it results in (what looks like) an error page from your hosting provider:

Error page returned when accessing the www subdomain

But is htaccess file correct?

Strictly speaking, the external redirect (www to non-www) should be near the top of your file, before the internal rewrites.

However, you have other problems with these directives. In fact, I'd question whether mod_rewrite is even enabled (or this is the wrong .htaccess file?), since your first RewriteRule is likely to prevent access to your site (with a 403 or 500 error):

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ %{REQUEST_FILENAME} [L]
# invalid code - and useless if the ^ and % were joined

You've commented that it's "invalid code", but it's not commented out. In order to prevent further rewrites when accessing physical files, you should use a single hyphen in the RewriteRule substitution. For example:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

You can't rewrite to a file system path (ie. the value of the REQUEST_FILENAME server variable) in a .htaccess context. This is likely to be inaccessible and result in a system generated 403 Forbidden.

RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index.php -f
RewriteRule ^ %{REQUEST_FILENAME}/index.php [L]
# invalid code as the second condition can NEVER happen and the Rule is flawed (regex of ^ !!!).

I'm not sure of the reasoning behind your comment, since the second condition CAN happen. However, this should be unnecessary, providing you've stated DirectoryIndex index.php (which you have).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.