Mod Rewrite for Subdomain

Discussion in 'Apache' started by mateobus, Jan 24, 2011.

  1. #1
    Hey All!

    I am trying to configure mod_rewrite such that I can access php scripts without showing the .php extension (/mysite/ calls /mysite.php). After finding a tutorial online, I was able to achieve this. However, I noticed that this is not working for subdomains that I create on my website. Here is the .htaccess file that I am using:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^([^/]+)/$ $1.php

    I have dropped this file into the subdomain's root folder, however I am getting 404 errors. Can anyone help decipher that regular expression and then suggest any modifications I would need to make for the subdomain?

    Thank you all in advance!
     
    mateobus, Jan 24, 2011 IP
  2. wpconfig

    wpconfig Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you can change the Apache virtualhost settings you can activate MultiViews, then you don't need any rewrites; it works default then.

    However, you are almost there; this should work;


    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)/$ $1.php
     
    wpconfig, Jan 25, 2011 IP
  3. mateobus

    mateobus Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply, wpconfig.

    I tried adding a .htaccess file to my subdomain directory and I am still getting a 404 error. Can I even use a .htaccess file in the subdomain or do I need to add that to the .htaccess file in the root of my hosting? My hosting is configured as followed

    /html/ --websites stuff goes here
    /html/subdomain/--subdomain stuff goes here

    Thanks again for your help
     
    mateobus, Jan 25, 2011 IP