I have been attempting to correct an issue that I'm experiencing with WordPress. Following the advice on the WordPress.SE site I've tried to resolve it with an .htaccess rewrite rule, but for some reason I cannot get the rule to quite work properly.

I've shorted my urls here for legibility. My wordpress site is at /r.info/blogs/th. I installed the network features to allow a friend to blog under the same site without making a second installation. Unfortunately the new url for his part of the site comes out as /r.info/blogs/th/st which is not what I had in mind. I would prefer /r.info/blogs/st.

Moving the site itself seems very difficult without data loss, I've already investigated this through WP.SE.

-bash-3.2$ cat .htaccess
#RewriteEngine On    # Turn on the rewriting engine
#RewriteRule    /blogs/st/(.*)$    /blogs/th/st/$1    [NC]

# BEGIN wtwp_cache
<IfModule mod_mime.c>

        # Text
        AddType text/css .css
        AddType application/x-javascript .js
        AddType text/html .html .htm
        AddType text/richtext .rtf .rtx
        AddType text/plain .txt
        AddType text/xml .xml

        # Image
        AddType image/gif .gif
        AddType image/x-icon .ico
        AddType image/jpeg .jpg .jpeg .jpe
        AddType image/png .png
        AddType image/svg+xml .svg .svgz

        # Video
        AddType video/asf .asf .asx .wax .wmv .wmx
        AddType video/avi .avi
        AddType video/quicktime .mov .qt
        AddType video/mp4 .mp4 .m4v
        AddType video/mpeg .mpeg .mpg .mpe

        # PDF
        AddType application/pdf .pdf

        # Flash
        AddType application/x-shockwave-flash .swf

        # Font
        AddType application/x-font-ttf .ttf .ttc
        AddType application/vnd.ms-fontobject .eot
        AddType application/x-font-otf .otf

        # Audio
        AddType audio/mpeg .mp3 .m4a
        AddType audio/ogg .ogg
        AddType audio/wav .wav
        AddType audio/wma .wma

        # Zip/Tar
        AddType application/x-tar .tar
        AddType application/x-gzip .gz .gzip
        AddType application/zip .zip

<IfModule mod_expires.c>
        ExpiresActive On

        # Text
        ExpiresByType text/css A31536000
        ExpiresByType application/x-javascript A31536000
        ExpiresByType text/html A3600
        ExpiresByType text/richtext A3600
        ExpiresByType text/plain A3600
        ExpiresByType text/xml A3600

        # Image
        ExpiresByType image/gif A31536000
        ExpiresByType image/x-icon A31536000
        ExpiresByType image/jpeg A31536000
        ExpiresByType image/png A31536000
        ExpiresByType image/svg+xml A31536000

        # Video
        ExpiresByType video/asf A31536000
        ExpiresByType video/avi A31536000
        ExpiresByType video/quicktime A31536000
        ExpiresByType video/mp4 A31536000
        ExpiresByType video/mpeg A31536000

        # PDF
        ExpiresByType application/pdf A31536000

        # Flash
        ExpiresByType application/x-shockwave-flash A31536000

        # Font
        ExpiresByType application/x-font-ttf A31536000
        ExpiresByType application/vnd.ms-fontobject A31536000
        ExpiresByType application/x-font-otf A31536000

        # Audio
        ExpiresByType audio/mpeg A31536000
        ExpiresByType audio/ogg A31536000
        ExpiresByType audio/wav A31536000
        ExpiresByType audio/wma A31536000

        # Zip/Tar
        ExpiresByType application/x-tar A31536000
        ExpiresByType application/x-gzip A31536000
        ExpiresByType application/zip A31536000
<FilesMatch "\.(?i:css|js|htm|html|rtf|rtx|txt|xml|gif|ico|jpg|jpeg|jpe|png|svg|svgz|asf|asx|wax|wmv|wmx|avi|mov|qt|mp4|m4v|mpeg|mpg|mpe|pdf|swf|ttf|ttc|eot|otf|mp3|m4a|ogg|wav|wma|tar|gz|gzip|zip)$">
        <IfModule mod_headers.c>
                Header set Pragma "public"
                Header append Cache-Control "public, must-revalidate, proxy-revalidate"
                Header unset ETag
<FilesMatch "\.(?i:css|js|gif|ico|jpg|jpeg|jpe|png|pdf|swf|ttf|ttc|eot|otf)$">
    <IfModule mod_headers.c>
                Header unset Set-Cookie
# END wtwp_cache

# BEGIN wtwp_security
<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /blogs/th/st/
        RewriteRule ^wp-admin/includes/ - [F,L]
        RewriteRule !^wp-includes/ - [S=3]
        RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
        RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
        RewriteRule ^wp-includes/theme-compat/ - [F,L]
<Files "wp-config.php">
        Order allow,deny
        Deny from all
Options -Indexes
# END wtwp_security

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blogs/th/
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

# END WordPress

I've tried including something simple like RewriteRule ^r.info/blogs/st/$ r.info/blogs/th/st/ at the top of the file (with an engine on line as well).

I also tried, per the suggestion on WP.SE:

RewriteCond %{REQUEST_URI} "/th/st/"
RewriteRule (.*) $1 [L]

But I'm assuming I insufficiently understand what the rule is in fact doing. I'm getting 500 errors when using the above.


You can use the following Rewrite Rule:

RewriteRule r.info\/blogs\/st\/?(.*)$ r.info/blogs/th/st/$1 [L]

Make sure no rule before this rule which has the [L] option gets triggered, because if it does, htaccess will never reach this rule.

  • Of course the difficulty is incorporating this into the rules that I demonstrated so that WordPress continues to work properly – Stephen Jun 1 '14 at 20:58
  • 1
    You can add the rule at the end (after all the other rules). If it doesn't seem to work (clearing browser cache is important while testing this), just move the rule above one line until it works. – Chirag Bhatia - chirag64 Jun 2 '14 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.