Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+7 votes
509 views
in Q2A Core by

This seems to be a non-issue for many people (read: I can't find an answer), but I would like to update the following htaccess code to not only remove the 'www' from the URL, but also any sub-directories that are accessed.

# In order for the web server to process this file it must be renamed to ".htaccess"

Options -Indexes

DirectoryIndex index.php

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} libwww-perl.*

RewriteRule .* – [F,L]

#RewriteBase /

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$

RewriteRule . %1/%2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]

</IfModule>

With this, http://www.example.com/any/ resolves fine, but I want it to redirect to http://example.com/any/ as with the root.

1 Answer

0 votes
by
test this at https://htaccess.madewithlove.com/
 

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP_USER_AGENT} libwww-perl.*

RewriteRule .* – [F,L]

RewriteCond %{REQUEST_URI} ^www.example.com

RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www.example.com

RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

</IfModule>
...