DigitalBerg
  • HOME
  • WINDOWS VPS
  • VIRTUAL SERVER
    • Virtuozzo VPS
    • OpenStack VPS
    • Amazon Lightsail VPS
    • VMware VPS
  • DEDICATED SERVER
    • INSTAND DEDICATED SERVERS
    • HOSTING DEDICATED SERVERS
    • DEDICATED ENTERPRISE SERVERS
    • INFRA. DEDICATED SERVERS
    • DEDICATED GAME SERVERS
  • MORE
    • SSL SHOP
    • FREE SSD WEBHOSTING
  • LOGIN
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu

We talking about Cloud

Web Hosting & Cloud Services
Celebrate the power and freedom of Open Source
with Open Source Cloud Servers starting at only £10/mo £5/mo.

How to Make Custom Rewrite Rules in WordPress

You may notice that any custom rewrite rules you make for specific folder paths under your site’s domain will simply produce 404 errors on your WordPress blog.

To fix this, try the following:

  1. Open your .htaccess file. The code for WordPress will look like this:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
  2. List paths which should not obey WordPress rewrites in the RewriteCond %{REQUEST_URI} !^/(path1|path2|path3) [NC]. Here is the fix in action:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteCond %{REQUEST_URI} !^/(abc|xxx|events/go-to-town) [NC]
    
    RewriteRule . /index.php [L]
    
    RewriteRule ^abc/$ "http://wordpress.com/" [R=301,L]
    RewriteRule ^xxx/$ "http://support.hostgator.com/" [R=301,L]
    RewriteRule ^events/go-to-town/$ "http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=whatever" [R=301,L]
    
    </IfModule>
    # END WordPress
    Note: This code works for WordPress blogs hosted on their own domain (primary, addon, subdomain); however, the code must be changed to work with a blog installed in a subfolder without its own domain.
    
    To make this work with a www.mydomain.com/blog type address, you just need to tweak one line:
    
    RewriteCond %{REQUEST_URI} !^/(blog/abc|blog/xxx|blog/events/go-to-town) [NC]
    
    The rewrite rules remain the same.
  3. Then you can add your custom rewrite rules above the </IfModule>.
Warning! Each line of code in the .htaccess file must have its own new line in the file. Do not allow a long line to break and continue on a new line or your code will have unexpected behavior. For example:

RewriteRule ^events/go-to-town$ "http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=whatever" [R=301,L]

This should all be one line.
Get in Touch

Let me know if you got an interesting project and want to work together!

digitalberg.com

DigitalBerg fuels apps, websites, emails, and much more for numerous clients globally.

Virtual servers to dedicated servers at affordable prices that any hostinger student can afford.

Services

  • Web Hosting
  • Virtual Server
  • Instant Servers
  • Dedicated Servers
  • Enterprise Servers
  • Infrastructure Servers
  • Gaming Servers
  • SSL Shop

SUPPORT

  • Contact Us
  • Wiki
  • FAQ
  • Blogs

Company

  • About Us
  • Partners
  • Privacy Policy
  • Term of Service
  • Acceptable Use Policy
  • Green Hosting
  • Data center

CLIENT AREA

  • Registration
  • Client Area
  • Server Status
  • Support

OTHER SERVICES

  • Domain Registration
  • Transfer Domain
  • Add ons / Management
  • SSL Certificates
  • Server Monitoring
  • Server hardware
DigitalBerg review
DigitalBerg review
© Copyright - DigitalBerg | From January 1st 2015, in accordance with the amended Directive 2006/112/EC, prices inclusive of VAT may vary depending on the country of residence of the customer.
  • Link to Facebook
  • Link to X
  • Link to LinkedIn
Link to: How to Export and Import in WordPress Link to: How to Export and Import in WordPress How to Export and Import in WordPress Link to: Unable to Upload Image to Post Link to: Unable to Upload Image to Post Unable to Upload Image to Post
Scroll to top Scroll to top Scroll to top