#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    41
    Rep Power
    14
    First off, I'm trying this using apache on Win2k, so I'm not even sure if it'll work.

    The server one of my sites is hosted on doesn't allow me to access a file without an extension, so in the .htaccess file, how can I force it so that all attempts at accessing /dir/file redirect to /dir/file.php?
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>I'm trying this using apache on Win2k

    I don't know if you can use mod_rewrite on Win2k either. Here is the code anyway..

    #############################################

    #http://www.yourdomain.com/.htacces
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/([/A-Za-z0-9_]*)?([A-Za-z0-9_]+)$
    RewriteRule ^(.*) http://www.yourdomain.com/$1.php [R]

    #############################################

    Note, all request (file or dir) WITHOUT a trailing slash or WITHOUT a dot will be handled by this Rewrite rules and EXTERNAL redirect and add .php to the end.

    Take a close look at the following examples and see what will my rewrite rules do for you:

    1) http://www.yourdomain.com/foo -> http://www.yourdomain.com/foo.php

    2) http://www.yourdomain.com/foo/ -> http://www.yourdomain.com/foo/ (no change as long as foo directory exists)

    3) http://www.yourdomain.com/foo/bar -> http://www.yourdomain.com/foo/bar.php

    4) http://www.yourdomain.com/foo/bar/ -> http://www.yourdomain.com/foo/bar/ (no change as long as bar directory exists)

    5) http://www.yourdomain.com/foo/bar/123/456 -> http://www.yourdomain.com/foo/bar/123/456.php

    6) http://www.yourdomain.com/foo/bar/123/456/ -> http://www.yourdomain.com/foo/bar/123/456/ (no change as long as 456 exists)

    7) http://www.yourdomain.com/foo/bar.html -> http://www.yourdomain.com/foo/bar.html (no change, note the file bar.html, as it has a dot, so it displays as is)

    If you can tell me what is the EXACT NAME of that "dir" and its URL path relative to your http://www.yourdomain.com, it would run alot faster. Be sure to provide more example, not just /dir/file. I also need to know whether it's just /dir/file or /dir/subdir/file.

    Finally, if apache on win32 can't use mod_rewrite, simply ignore this thread.

    [This message has been edited by freebsd (edited October 22, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    41
    Rep Power
    14
    All the files will be located in the root directory. I tried what you sent me, but I guess I was wrong in what I wanted. The htaccess literally forwards the user to the file (people accessing /test are transported to /test.php), but I want it so that it is always just /test, so that I can use the script like /test/key1/value1/key2/value2, and so on. Thanks. I knew I should have paid more attention to regex in class...
  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>but I want it so that it is always just
    /test

    How many different name of /test are there? Would it be /another_test ? Since you haven't given enough examples, I still don't know exactly what you really want.

    >>people accessing /test are transported to /test.php

    I am not sure what you mean by "transported"? Do you want the browser location stays the same as is (i.e. /test) and INTERNAL redirect to /test.php? If so, change the [R] to [L].

    RewriteRule ^(.*) http://www.yourdomain.com/$1.php [L]

    Test this first, if it doesn't work, just take a look at my another post in this forum -> http://www.devshed.com/Talk/Forums/F...ML/000274.html

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    41
    Rep Power
    14
    My overall goal is to make it so that the file test.php is extensionless to the user. I then plan to replace ? with / as the query designation to make the site search engine friendly.

    So:
    http://www.mydomain.com/file.php?this=that

    Would become:
    http://www.mydomain.com/file/this/that

    However, Apache keeps trying to access a directory for /file/this/that, instead of the file file.php

    I can do /file.php/this/that just fine, but without the extension, the server keeps trying to access a directory.

    Thanks for the support, I REALLY appreciate it.
  10. #6
  11. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>My overall goal is to make it so that the file test.php is extensionless to the user

    You said your host doesn't allow you to access a file without extension, I think you interpret this incorrectly. Were you trying to say that a file without extension can be treated as a PHP script? If so, try this:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/([/A-Za-z0-9_]*)?([A-Za-z0-9_]+)$
    RewriteRule ^(.+) http://www.yourdomain.com/$1 [T=application/x-httpd-php,L]

    i.e. http://www.yourdomain.com/file/this/that

    Note, this just force your extensionless file , specifically "that", as a PHP file, not "file".

    >>to make the site search engine friendly

    Here say it all -> http://www.devshed.com/Talk/Forums/F...ML/000274.html Since you are asking for the same thing, I am not going to repost the exact content.

IMN logo majestic logo threadwatch logo seochat tools logo