skip to Main Content

I am rewriting sub-folders of my website to sub-domain via bellow code in Apache vhost file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www. example.com
RewriteCond %{HTTP_HOST} ^(www.)?(([^.]+).){1}example.com$
RewriteCond /var/www/example.com/web/crm/build/%3 -d
RewriteRule ^/(.*) /crm/build/%3/$1

so https://example.com/web/crm/folder = https://folder.example.com

Also i am using .htaccess to hide /index.php/ in codeigniter url

RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
AddDefaultCharset utf-8

example.com/web/crm/folder works fine

folder.example.com i get 505 internal error which gets fine once i delete lines in .htaccess or just simple access website via folder.example.com/index.php/ (Nothing is showing up in log)

I want to fix rewrite conflict for sub domain

2

Answers


  1. Chosen as BEST ANSWER

    Fixed

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
      ErrorDocument 404 /index.php
    </IfModule>
    

  2. OK, two suggestions:

    1. It would be nice to know what specific server-side error is causing the HTTP 505.

      Please copy/past the exact message from your server log into your post.

    2. It would also be nice to know exactly how your rewrite rules are being interpreted.

      Please enable logging as follows:

    How to debug Apache mod_rewrite

    Apache Module
    mod_rewrite

    mod_rewrite offers detailed logging of its actions at the trace1 to
    trace8 log levels. The log level can be set specifically for
    mod_rewrite using the LogLevel directive: Up to level debug, no
    actions are logged, while trace8 means that practically all actions
    are logged.

    Example

    LogLevel alert rewrite:trace6
    

    George Samarguliani added this comment, which explains the HTTP 505 error:

    apache does not start after adding rewrite log rule in vhost file Job
    for httpd.service failed because the control process exited with error
    code. See “systemctl status httpd.service” and “journalctl -xe” for
    details.

    I copied/pasted the vhost snippet above into the first handy Apache config validator, https://htaccess.madewithlove.be/, and got this:

    htaccess.MadeWithLove validator

    So now at least we know what’s causing the server-side error: Apache vhost configuration.

    NEW SUGGESTIONS:

    1. As far as the “index.php”, I don’t even think you need or want a re-write rule.

      Just configure “DirectoryIndex”, like this:

      <Directory /myapp>
        DirectoryIndex index.php
      </Directory>
      
    2. As far as the rest of the URL (e.g. “http://example.com/web/crm/build/`), please update your post with before/after examples of how you would like to the redirect to actually work.

    3. There are lots of good “howtos”, with good examples, for using .httaccess/mod_rewrite rules. For example:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search