0

I recently changed my hosting. The old server had php 5.3 and the newer has php 5.6. This change in host is one step towards making my website compatible with php 7.

However I have come across an issue with htaccess redirect.

My htaccess file looks like below

DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On

RewriteRule ^company/([0-9]+)/?$    company.php?company_id=$1 [L]

So when I go to page with url mydomain.com/admin/company/92

I don't seem to get the redirected URL as required i.e. mydomain.com/admin/company.php?company_id=92

This is some of the output from printing $_SERVER

    [REDIRECT_SCRIPT_URL] => /admin/company/92/
    [SCRIPT_FILENAME] => /htdocs/myproj/admin/company.php
    [REDIRECT_URL] => /admin/company.php/92/
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => 
    [REQUEST_URI] => /admin/company/92/
    [SCRIPT_NAME] => /admin/company.php
    [STATUS] => 200
    [ORIG_PATH_INFO] => /92/
    [ORIG_PATH_TRANSLATED] => /htdocs/myproj/admin/company.php
    [PHP_SELF] => /admin/company.php
    [argv] => Array
        (
        )

    [argc] => 0
)

I have got php 5.3 on my local and the same code works fine on my local. How do I resolve this issue?

2
  • in ^company the ^ sticks it to the start of the string. So anything before company will make it fail to match. You could change it to RewriteRule /company/([0-9]+)/?$ /company.php?company_id=$1 [L] for example Commented Sep 21, 2017 at 10:24
  • I tried removing ^ but I still don't get anything in QUERY_STRING Commented Sep 21, 2017 at 10:33

1 Answer 1

1

This is most likely effect of option MultiViews turned on by default new host.

You can turn it off like this:

DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /admin/

RewriteRule ^company/([0-9]+)/?$ company.php?company_id=$1 [L,NC,QSA]

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Hi Anubhav, I changed as above but still don't get any value in the [QUERY_STRING] => .... On my local with php 5.3 I can still see [QUERY_STRING] => company_id=92
You are right. It doesn't seem to be enabled at directory level!!!! Thank you. I will call my hosting company now and get it enabled. I think most likely that is the issue. How silly of me of not to think to check that first.
My bad - htaccess is enabled but I was making changes in a wrong file. I made above changes in the correct file now and I get 500 internal server error (i.e. after adding -mulitviews and [L, NC, QSA]. Please advise. Thank you so much for you time.
Are there any other changes you can think of? I have tried speaking to hosting customer care but i haven't had any luck. Thank you.
I put -MultiViews again and with [L, NC, QSA, R] - when I go to mydomain.com/admin/company/92 it redirects me to mydomain.com/kunden/homepages/121/46545/htdocs/mypoject/admin/company.php?company_id=92 .... so its getting there just need to ensure that redirect only goes to mydomain/admin/company.php?company_id=92
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.