dkb
dkb

Reputation: 131

.htaccess rewrite rule for same words


I have two rules causing problems:

RewriteRule ^posts$ posts.php
RewriteRule ^posts/create$ postscreate.php

I know that I could use "post/create" but these are just two rules out of more that are having all the same problem.

I worked with this rules perfectly on localhost (XAMPP).

However, once I moved the files to my hoster and visited "sub.domain.com/posts/create" it redirects me to posts.php instead of postscreate.php.

Why does it work fine on localhost but not on my hoster? And how can I fix it?

My full .htaccess looks like this (with the two rules only):

AddType application/x-httpd-php .html
RewriteBase /
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://sub.domain.com/$1 [R=301,L]

Options -Indexes

RewriteRule ^posts$ posts.php
RewriteRule ^posts/create$ postscreate.php

The .htaccess on localhost is exactly the same except the https rules. I also tried the .htaccess without the https rules on my hoster but it still didn't work.

Upvotes: 1

Views: 119

Answers (1)

anubhava
anubhava

Reputation: 784898

Why does it work fine on localhost but not on my hoster? And how can I fix it?

It is most likely due to option MultiViews being turned on on hoster but turned off on localhost.

To disable this use this line on top of .htaccess:

Options -MultiViews

Option MultiViews (see http://httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /file is the URL then Apache will serve /file.html.

Upvotes: 1

Related Questions