• Hi,

    I am facing issue with the url redirect.

    When i added url redirect code to the .htacess file the code working successful , but i can not upload image at admin.
    I need to add the url redirect rule at the .htacess via functions.php but i am not getting how to do that.
    Previously posted forums for the same topic gave me the following code

    function ftc_flush_rewrites() {
    global $wp_rewrite;
     $wp_rewrite->flush_rules();
    }
    
    function ftc_add_rewrites() {
    global $wp_rewrite;
    	$wp_rewrite->non_wp_rules = array( '(.*)’(.*)$' => '$1$2' );
    
    }
    
    add_action('init', 'ftc_add_rewrites');
    add_action('admin_init', 'ftc_flush_rewrites');

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been damaged by the forum’s parser.]

    Which is not working for me.

    Please guide me how to do that.
    My current version for the wordpress is 4.5

Viewing 6 replies - 1 through 6 (of 6 total)
  • Personally, I never needed to add a redirect in the functions.php file. Only in htaccess. Are you trying to redirect a specific url such as https://site.com/mypage or do you want a wildcard that will redirect everything?

    Thread Starter thefastestmedia

    (@thefastestmedia)

    actually I added the code at the .htaccess file.
    and then i posted the image at the post/media the image can not uploaded and giving me error.
    After receiving error i remove the code and then uploaded image at that time image was successfully uploaded.
    that’s why i need to add the rule via function.php , over there we can check the condition.

    Thread Starter thefastestmedia

    (@thefastestmedia)

    i want to remove the apostrophe from URL and then redirect to the normal one.

    You may not have correctly added it to the htaccess. Because typically it is advised that redirects are done via htaccess. Would you share the code that you added to htaccess which caused the error?

    Thread Starter thefastestmedia

    (@thefastestmedia)

    Hi Davood Dehnavi,

    I have added following code at the htaccess`# BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteRule ^(.*)’(.*)$ /$1$2 [R=301,L]
    RewriteRule ^(.*)'(.*)$ /$1$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress`

    its working for redirect , but it is not allowed image to upload from admin.

    Try going back to the default WP code. And see if you still get the error.

    Default htaccess

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    If you still have the error then it is a permissions error with the content and/or uploads directory causing your problem.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘need to add redirect rule via function.php’ is closed to new replies.