Support » Fixing WordPress » Can I override WP permalinks with custom external url in .htaccess ?

  • Resolved duodesign

    (@duodesign)


    Hi everyone !

    The loooong title sums it up pretty well, but here are a couple more details about my problem :

    Before switching to WordPress, we had a website build from scratch, in which an .htaccess file handled all the URL rewriting. Among other rules, we created a couple of clean links, used on QRcodes, printed documents, etc. For example :
    mysite.com/ECvideo used to redirect to a youtube video, and mysite.com/MYdownload pointed directly to a downloadable content.

    Since I opened the new WP site (with a custom theme based on Twentysixteen), WordPress mistakes these links for pages permalinks, which leads to 404 errors.

    I tried to include our old redirection lines in the new .htaccess file, within and outside the <IfModule mod_rewrite.c>, but it doesn’t work.

    I would like to avoid using a plugin (the website is pretty loaded with plugins), but I didn’t find anything besides topics about customizing permalinks structure for SEO or Custom Post Type…

    Any help would be appreciated 🙂 !

    • This topic was modified 2 years ago by  duodesign.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Pioneer Web Design

    (@swansonphotos)

    Place the Redirect Rules above the WordPress Permalink Rules. Then they are acted on prior.

    See: Case-Insensitive RedirectMatch

    
    # Redirect First
    <IfModule mod_rewrite.c>
    RedirectMatch 301 (?i)/post-slug/?$ http://othersite.com/some_url/
    </IfModule>
    
    # 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
    

    See this comment for further explanation.

    duodesign

    (@duodesign)

    Hi Pioneer Web Design,

    Thanks for your answer, its works !
    I had already try to put my rules before the WordPress Permalink Rules, but I was using RewriteRule instead of RedirectMatch.

    Thanks again, have a great day !

    Edit :
    The solution of modifying the .htaccess does work, but the .htaccess file is overwritten by WordPress every time a update is made on a page / a page is created / or other modifications.

    So I had to write the custom URLs in another .htacess file, and put it in the parent folder (the same as /www). I’m not sure it’s a really good thing to do, but it works.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can I override WP permalinks with custom external url in .htaccess ?’ is closed to new replies.