0

We have made a flyer were a URL is printed at which looks like this:

mycompany.de/special

But if a user actually enters this URL, then he is getting redirected to the startpage https://www.mycompany.de/index.php instead of getting redirected to https://www.mycompany.de/special

This is my .htaccess so far, it forces https and www:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

That works almost as expected, the only problem is that /special is getting removed and replaced by /index.php. The question is, why is special getting replaced?

Black
  • 18,150
  • 39
  • 158
  • 271
  • Did you check this https://stackoverflow.com/questions/10489895/http-to-https-through-htaccess ? – Amit Verma Dec 12 '18 at 15:33
  • Possible duplicate of [.htaccess redirect all pages to new domain](https://stackoverflow.com/questions/1945568/htaccess-redirect-all-pages-to-new-domain) – Pedro Rodrigues Dec 12 '18 at 15:33
  • @starkeen, how is this related to my question? – Black Dec 12 '18 at 15:34
  • @PedroRodrigues, this is not related to my question at all, how is this a duplicate? – Black Dec 12 '18 at 15:35
  • What exactly is not working for you? – Amit Verma Dec 12 '18 at 15:47
  • Im not sure what informations are missing, I added all necessary infos to my question @starkeen. – Black Dec 12 '18 at 15:47
  • 1
    Sorry but the rule you posted looks ok and it works for me. – Amit Verma Dec 12 '18 at 15:55
  • Is `/special` a real directory? – Amit Verma Dec 12 '18 at 15:58
  • You're joking right? Not related to your question, how can you argument that may I ask. It is related to your question, and you should not expect any further comments from me on this, unless you state what is that your not being able to achieve. Don't expect someone to do your work, there's plenty of gentleman waiting to help you; help them doing it. I'm out. – Pedro Rodrigues Dec 12 '18 at 16:01
  • 1
    @pedroRodrigues by the way , "Redirecting to new site" was not the question :) – Amit Verma Dec 12 '18 at 16:03
  • @starkeen, No /special is just a route. I am working with Magento and created the site as a CMS page. The actual content is stored in the database. – Black Dec 12 '18 at 16:08
  • 2
    I think it's Magento the problem : .htaccess should work. There is something else that redirect the page after it. Or provide full .htaccess if there is other conditions. – Shim-Sao Dec 12 '18 at 16:14
  • @Shim-Sao, my condition is at the bottom of the .htaccess file, so It can't get overwritten. I will check if magento is the cause by commenting out code at the index.php – Black Dec 12 '18 at 16:16
  • 1
    I don't understand why it can't get overwritten ? – Shim-Sao Dec 12 '18 at 16:20
  • 1
    @Shim-Sao, you are right, that was a dumb comment. It CAN be overwritten, and it was overwritten :/ I found the solution and will post it – Black Dec 12 '18 at 16:21
  • Rule that you've shown must be placed before all other rules and then clear your browser cache. – anubhava Dec 12 '18 at 16:29

1 Answers1

0

I was able to solve it with this code:

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_URI} !^/special
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php/%{REQUEST_URI} [L]
Black
  • 18,150
  • 39
  • 158
  • 271