Search code examples
phpapache.htaccessipb

static URL Rewriting the subdir


i already shearch, and i never found this that i am asking, soo i want to know if it is even possible... or not ...

  • I am testing this in IPB.Board 3.4.5, with the app IP.Downloads.

  • I have this static url in my site that users can acess to download one file:

    mysite.com/files/file/2-filename.txt

  • The original dynamic url is something like:

    .../?app=downloads&showfile=2

  • The change of the url is made by that app (IP.Downloads)...

    • i want to change it to url:

      mysite.com/text/2-filename.txt

  • so when the user insert in browser

    1 mysite.com/text/2-filename.txt

    • they see the file

    2 mysite.com/files/file/2-filename.txt

    • they are rewrite to mysite.com/text/2-filename.txt
      • and see the file.
How can i do that? change from ( /files/file/ ) to ( /text/ ) ... that can be made by .htaccess or i have to change the app files? or is impossible?

::UPDATE::

I have done it! without .htaccess , i change the core files that rewrite the url...

see the Answer below ...


Thanks for any help.


Solution

  • I made it by changing the core files ... it is more simple for me, so i use this way. thanks @ravi-thapliyal for trying to help making this by .htaccess, but i prefer this way ...

    First open this file:

    {forum-root}/admin/applications_addon/ips/downloads/extensions

    1. Edit this code ['idmshowfile'] in the $_SEOTEMPLATES = array

      • This will tell the server that when the user go to (myserver.com/text/) they want to see the file...

      • 'idmshowfile' => array(

           'app'          => 'downloads',
        
           'allowRedirect' => 1,
        
           'out'          => array( '/app=downloads(&|&)showfile=(.+?)(&|$)/i', 'text/$2-#{__title__}/$3' ),
        
           'in'           => array( 
        
               'regex'        => "#/text/(\d+?)-#i",
        
               'matches'  => array( 
        
                   array( 'app'       , 'downloads' ),
        
                   array( 'showfile'  , '$1' ))
        
                   ) 
        
           ),
        
    2. And add this code to $_SEOTEMPLATES = array, in any position ...

      • this will tell to server that if the user go to (myserver.com/files/file/) they will be rewrite the url (myserver.com/text/) , and see the file.

      • 'idmshowfile2' => array(

           'app'          => 'downloads',
        
           'allowRedirect' => 1,
        
           'out'          => array( '/app=downloads(&|&)showfile=(.+?)(&|$)/i', 'text/$2-#{__title__}/$3' ),
        
           'in'           => array( 
        
               'regex'        => "#/files/file/(\d+?)-#i",
        
               'matches'  => array( 
        
                   array( 'app'       , 'downloads' ),
        
                   array( 'showfile'  , '$1' ))
        
                   ) 
        
           ),
        

    You can add as many rewrites as you want to the Forum, and create nice and friendly SEO URL.

    Of course i know that this file can be overwrite in future updates of the app, soo i will make backup, and if possibel create an hook or app to make this (... if possibel).