.htaccess URL为Yourls重写失败-在此服务器上找不到请求的URL

本迪科

Apache / PHP新手问题:

我正在尝试进行安装http://yourls.org/

一切似乎都已安装好,并且我可以添加新的URL并缩短它们。

但是链接生成了404。例如,http://mydoma.in/4应该重定向但不重定向

.htaccess文件如下所示:

# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /yourls-loader.php [L]
</IfModule>
# END YOURLS

如果我浏览到该页面,http://mydoma.in/yourls-loader.php它的确会将我重定向到主页。

我猜测ID需要有一个参数,该参数需要通过重写传递给 /yourls-loader.php

/yourls-loader.php如下所示:

<?php
// Handle inexistent root favicon requests and exit
if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
    header( 'Content-Type: image/gif' );
    echo base64_decode( "R0lGODlhEAAQAJECAAAAzFZWzP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0PUQAgSGoNQFt0LWTVOE6GuX1H6onTVHaW2tEHnJ1YxPc+UwAAOw==" );
    exit;
}

// Handle inexistent root robots.txt requests and exit
if ( '/robots.txt' == $_SERVER['REQUEST_URI'] ) {
    header( 'Content-Type: text/plain; charset=utf-8' );
    echo "User-agent: *\n";
    echo "Disallow:\n";
    exit;
}

// Start YOURLS
require_once( dirname( __FILE__ ) . '/includes/load-yourls.php' );

// Get request in YOURLS base (eg in 'http://site.dom/yourls/abcd' get 'abdc')
$request = yourls_get_request();

// Make valid regexp pattern from authorized charset in keywords
$pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() );

// Now load required template and exit

yourls_do_action( 'pre_load_template', $request );

// At this point, $request is not sanitized. Sanitize in loaded template.

// Redirection:
if( preg_match( "@^([$pattern]+)/?$@", $request, $matches ) ) {
    $keyword = isset( $matches[1] ) ? $matches[1] : '';
    $keyword = yourls_sanitize_keyword( $keyword );
    yourls_do_action( 'load_template_go', $keyword );
    require_once( YOURLS_ABSPATH.'/yourls-go.php' );
    exit;
}

// Stats:
if( preg_match( "@^([$pattern]+)\+(all)?/?$@", $request, $matches ) ) {
    $keyword = isset( $matches[1] ) ? $matches[1] : '';
    $keyword = yourls_sanitize_keyword( $keyword );
    $aggregate = isset( $matches[2] ) ? (bool)$matches[2] && yourls_allow_duplicate_longurls() : false;
    yourls_do_action( 'load_template_infos', $keyword );
    require_once( YOURLS_ABSPATH.'/yourls-infos.php' );
    exit;
}

// Prefix-n-Shorten sends to bookmarklet (doesn't work on Windows)
if( preg_match( "@^[a-zA-Z]+://.+@", $request, $matches ) ) {
    $url = yourls_sanitize_url( $matches[0] );
    if( $parse = yourls_get_protocol_slashes_and_rest( $url, array( 'up', 'us', 'ur' ) ) ) {
        yourls_do_action( 'load_template_redirect_admin', $url );
        $parse = array_map( 'rawurlencode', $parse );
        // Redirect to /admin/index.php?up=<url protocol>&us=<url slashes>&ur=<url rest>
        yourls_redirect( yourls_add_query_arg( $parse , yourls_admin_url( 'index.php' ) ), 302 );
        exit;
    }
}

// Past this point this is a request the loader could not understand
yourls_do_action( 'loader_failed', $request );
yourls_redirect( YOURLS_SITE, 302 );
exit;

yourls_get_request()函数如下所示:

function yourls_get_request() {
    // Allow plugins to short-circuit the whole function
    $pre = yourls_apply_filter( 'shunt_get_request', false );
    if ( false !== $pre )
        return $pre;

    static $request = null;

    yourls_do_action( 'pre_get_request', $request );

    if( $request !== null )
        return $request;

    // Ignore protocol & www. prefix
    $root = str_replace( array( 'https://', 'http://', 'https://www.', 'http://www.' ), '', YOURLS_SITE );
    // Case insensitive comparison of the YOURLS root to match both http://Sho.rt/blah and http://sho.rt/blah
    $request = preg_replace( "!$root/!i", '', $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 1 );

    // Unless request looks like a full URL (ie request is a simple keyword) strip query string
    if( !preg_match( "@^[a-zA-Z]+://.+@", $request ) ) {
        $request = current( explode( '?', $request ) );
    }

    return yourls_apply_filter( 'get_request', $request );
}
拉维·杜里亚2

为了使用mod_rewrite,您可以在终端中键入以下命令:(假设您在基于debian的服务器上)

$sudo a2enmod rewrite

之后重启apache2

$sudo /etc/init.d/apache2 restart

要么

$sudo service apache2 restart

然后用你的 .htaccess

# BEGIN YOURLS
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /yourls-loader.php [L]
</IfModule>
# END YOURLS

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

.htaccess ReWriteRule-在此服务器上找不到请求的URL <重写的文件名>

来自分类Dev

htaccess URL重写-在服务器上找不到请求的URL

来自分类Dev

在此服务器django上找不到请求的URL

来自分类Dev

在此服务器上找不到请求的URL。Django的

来自分类Dev

在此服务器上找不到请求的URL /

来自分类Dev

htaccess重写程序,在此服务器上找不到文件

来自分类Dev

找不到404,在此服务器上的wordpress中找不到请求的URL << URL name >>

来自分类Dev

找不到404在此服务器上找不到请求的URL

来自分类Dev

错误消息:“找不到对象!在此服务器上找不到请求的URL。”

来自分类Dev

找不到Codeigniter PHP对象,在此服务器上找不到请求的URL

来自分类Dev

角度:返回URL错误:在此服务器上找不到请求的URL

来自分类Dev

在此服务器上找不到请求的 URL。在 php codeigniter 上

来自分类Dev

“在此服务器上找不到请求的URL /。” Heroku / Django

来自分类Dev

PHP Slim Framework:在此服务器上找不到请求的URL

来自分类Dev

AWS问题:在此服务器上找不到请求的URL

来自分类Dev

在此服务器上找不到请求的URL /test/index.php

来自分类Dev

在此服务器上找不到请求的URL / ProjectName / users。拉拉韦尔

来自分类Dev

AJAX:本地主机上的“在此服务器上找不到请求的URL”

来自分类Dev

laravel PHP项目中的“在此服务器上找不到请求的URL”错误

来自分类Dev

Wamp基本配置:“在此服务器上找不到请求的URL / my-site /。”

来自分类Dev

Symfony 4-路线:“在此服务器上找不到所请求的URL”

来自分类Dev

Google Play:在此服务器上找不到请求的URL

来自分类Dev

Android_Beta Testing_在此服务器上找不到请求的URL

来自分类Dev

Kohana在此服务器上找不到请求的URL / home

来自分类Dev

在此服务器上找不到请求的URL /。,django openshift

来自分类Dev

cs-cart在此服务器上找不到请求的URL

来自分类Dev

在此服务器上找不到请求的URL / practice / public / admin

来自分类Dev

Kohana_HTTP_Exception [404]:在此服务器上找不到请求的 URL Line/id

来自分类Dev

Elastic Beanstalk Laravel 部署返回请求的 URL /login 在此服务器上找不到

Related 相关文章

  1. 1

    .htaccess ReWriteRule-在此服务器上找不到请求的URL <重写的文件名>

  2. 2

    htaccess URL重写-在服务器上找不到请求的URL

  3. 3

    在此服务器django上找不到请求的URL

  4. 4

    在此服务器上找不到请求的URL。Django的

  5. 5

    在此服务器上找不到请求的URL /

  6. 6

    htaccess重写程序,在此服务器上找不到文件

  7. 7

    找不到404,在此服务器上的wordpress中找不到请求的URL << URL name >>

  8. 8

    找不到404在此服务器上找不到请求的URL

  9. 9

    错误消息:“找不到对象!在此服务器上找不到请求的URL。”

  10. 10

    找不到Codeigniter PHP对象,在此服务器上找不到请求的URL

  11. 11

    角度:返回URL错误:在此服务器上找不到请求的URL

  12. 12

    在此服务器上找不到请求的 URL。在 php codeigniter 上

  13. 13

    “在此服务器上找不到请求的URL /。” Heroku / Django

  14. 14

    PHP Slim Framework:在此服务器上找不到请求的URL

  15. 15

    AWS问题:在此服务器上找不到请求的URL

  16. 16

    在此服务器上找不到请求的URL /test/index.php

  17. 17

    在此服务器上找不到请求的URL / ProjectName / users。拉拉韦尔

  18. 18

    AJAX:本地主机上的“在此服务器上找不到请求的URL”

  19. 19

    laravel PHP项目中的“在此服务器上找不到请求的URL”错误

  20. 20

    Wamp基本配置:“在此服务器上找不到请求的URL / my-site /。”

  21. 21

    Symfony 4-路线:“在此服务器上找不到所请求的URL”

  22. 22

    Google Play:在此服务器上找不到请求的URL

  23. 23

    Android_Beta Testing_在此服务器上找不到请求的URL

  24. 24

    Kohana在此服务器上找不到请求的URL / home

  25. 25

    在此服务器上找不到请求的URL /。,django openshift

  26. 26

    cs-cart在此服务器上找不到请求的URL

  27. 27

    在此服务器上找不到请求的URL / practice / public / admin

  28. 28

    Kohana_HTTP_Exception [404]:在此服务器上找不到请求的 URL Line/id

  29. 29

    Elastic Beanstalk Laravel 部署返回请求的 URL /login 在此服务器上找不到

热门标签

归档