Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    .htaccess and mod_rewrite

    Ok, so I want to get a little fancy and change the extension of my files on my forum, from .php to .whatever.

    I've tried using the following;
    RewriteEngine On
    RewriteBase /forum/

    RewriteRule ^(.*).php $1.socal [R=301,L]

    RewriteRule ^(.*).socal $1.php [L]


    However Firefox tells me it will just continue to redirect and never stop.

    Any tips to getting this to work, or if it is even possible.

    Thanks in Advance.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    You don't need the line with the redirect in it. If you just want to provide the illusion of your files having a custom name, that solution will work(if you remove the redirecting line). If you want to physically rename the files and have PHP parse the new filenames you need to use an AddType directive in your .htaccess file like so:
    Code:
    AddType application/x-httpd-php .socal

  • #3
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So I would only need the following?

    RewriteEngine On
    RewriteBase /forum/
    RewriteRule ^(.*).socal $1.php [L]


    If I add the
    Code:
    AddType application/x-http-php .socal
    to the .htaccess, will that rename the files? or is that something I would have to do myself?

    I think I tried the above rewrite rule lastnight, and I was presented with the error 404 - the document /forum/index.socal could not be found.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by darkstar View Post
    So I would only need the following?

    RewriteEngine On
    RewriteBase /forum/
    RewriteRule ^(.*).socal $1.php [L]
    Yes, but you don't necessarily need the RewriteBase.
    Quote Originally Posted by darkstar View Post
    If I add the
    Code:
    AddType application/x-http-php .socal
    to the .htaccess, will that rename the files? or is that something I would have to do myself?
    You would have to do it yourself -- that is only if you want to change the actual name of the files. The mod_rewrite rule alone has the effect I believe you want, though.

  • #5
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, so this is what it should look like then.

    Code:
    RewriteEngine On
    RewriteRule ^(.*).socal $1.php [L]
    All I need it to do is mask the actual extension, giving it the appearance that it is something it is not.

    Tried the above, and it doesn't actually do anything, no masking of the extension.
    Last edited by darkstar; 11-18-2009 at 07:27 PM.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by darkstar View Post
    Ok, so this is what it should look like then.

    Code:
    RewriteEngine On
    RewriteRule ^(.*).socal $1.php [L]
    Yes, this works and is all you need. Make sure you have it in the ".htaccess" file in the directory you want it to affect.
    Quote Originally Posted by darkstar View Post
    All I need it to do is mask the actual extension, giving it the appearance that it is something it is not.

    Tried the above, and it doesn't actually do anything, no masking of the extension.
    You -do- understand that you will still be able to type in the .php filenames, right? It's just -also- allowing you to reference them as .socal filenames.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •