Note that there are some explanatory texts on larger screens.

plurals
  1. POhtaccess file to redirect non-www and https requests, and rewrite URLs
    primarykey
    data
    text
    <p>I'm trying to create my first .htaccess to make an URL rewrite and other things, but I've wasted two days searching for information and trying to make it work with no success.</p> <p>What I would like to achieve is the following:</p> <p><strong>1) redirect all the non-www URLs to the www URL</strong> (it seems a best practice for seo?)</p> <pre><code>domain.com --&gt; www.domain.com </code></pre> <p><strong>2) redirect all the https requests to http ones:</strong></p> <pre><code>https://www.domain.com --&gt; http://www.domain.com https://domain.com --&gt; http://www.domain.com </code></pre> <p><strong>3) rewrite my URLs to be SEO friendly, and eventually strip any trailing slash at the end of the address:</strong></p> <pre><code>www.domain.com/abc --&gt; www.domain.com/index.php?page=abc www.domain.com/abc/ --&gt; www.domain.com/abc </code></pre> <p><br> What I have so far, are three snippets which taken individually work:</p> <pre><code># 1) This should be correct, I hope! RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] </code></pre> <p><br></p> <pre><code># 2) This seems to work 100% right RewriteEngine On RewriteCond %{HTTPS} =on RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R,L] </code></pre> <p><br></p> <pre><code>#3) Major issues here RewriteEngine On RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L] </code></pre> <p>This works partially: it does what I want, but I get all relative paths broken when I put a trailing slash after the SEO friendly URL:</p> <pre><code>www.domain.com/abc OK www.domain.com/abc/ page gets displayed but all relative URL for css and images are broken </code></pre> <p><br> I don't even know how to combine the different rules in a single htaccess file to make them interact correctly.</p> <p>Sorry for the long explaination, this problem is becoming quite frustrating for me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload