The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hiding php extension
#1
Question 
Hello there,
I am working on to hide php extension from my site. I am succeeded with htacces file. But the problem is usercake files are basically redirecting to their pages  with php extension. How can I make usercake to redirect  without php extension. Will editing redirect function work?
  Reply
#2
I have not had much success hiding the file extension. I'm sure it can be done, but it creates all sorts of problems.
  Reply
#3
I will say that this is the closest I can get quickly to it working...
RewriteEngine on

#unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /4408/$1 [R=301,L]

#redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.*)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.*)\.php$ /4408/$1 [R=301,L]

#resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /4408/$1.php [L]

But from there you would need to figure out how to make php functions actually work. If you find out, let me know!
Btw, the 4408 is the folder that my project was in.

Normally you can move userspice from folder to folder without breaking anything and this would take that feature away.
  Reply
#4
Quote:But from there you would need to figure out how to make php functions actually work. If you find out, let me know!
Sorry for my inappropriate question, but what did you mean by that? Can you please explain?
Don't mind me Smile
  Reply
#5
So if you use the sample I gave you and put the right folder in there, your pages will load and everything will "look" decent" but for me, login didn't work etc. So I know it that's close, but something is still broken.
  Reply
#6
Oh, I already have my htacces working,
Code:
DirectoryIndex index default
# hide php extension
RewriteEngine On
# filename > filename.php (transparent)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [ QSA,NC,L ]
Redirect.php class
Code:
class Redirect {
  public static function to($location = null, $args=''){
    global $us_url_root;
    #die("Redirecting to $location<br />\n");
    if ($location) {
      if (!preg_match('/^https?:\/\//', $location) && !file_exists($location)) {
        foreach (array($us_url_root, '../', 'users/', substr($us_url_root, 1), '../../', '/', '/users/') as $prefix) {
          if (file_exists($prefix.$location)) {
            $location = $prefix.$location;
            $location = preg_replace('~/{2,}~', '/', $location);
            break;
          }
        }
      }
      if ($args) $location .= $args; // allows 'login.php?err=Error+Message' or the like
      if (!headers_sent()){
$location = str_replace('index.php','',$location);
$location = str_replace('.php','',$location);
        header('Location: '.$location);
        exit();
      } else {
$location = str_replace('index.php','',$location);
$location = str_replace('.php','',$location);
        echo '<script type="text/javascript">';
        echo 'window.location.href="'.$location.'";';
        echo '</script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url='.$location.'" />';
        echo '</noscript>'; exit;
      }
    }
  }

}
I get it worked. But i'd to edit some files manually like <form action="login.php"> to <form action="login">

I have a suggestion:
You can add a option in confi called "file extension for urls". As user define their preferred extension e.g.: php, html, (empty for no extension) and you can rewrite your files and replace somthing like
Code:
<a href="<?=$abs_us_root.$us_url_root.'users/account'.$file_ext.''?>">Account</a>
or
<form action="login<?=$file_ext?>">
I know it requires a hard work to rewrite all these scripts but I can assure that you don't have to do a hard work. Only few files which basically have <a> tags not require function need to be edited. You can do it and release in next release. I can be a tester or contributor if you want.
  Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)