htaccess 重写问题

htaccess 重写问题

我一直在尝试解决我在使用 WordPress 时遇到的问题。按照 WordPress.SE 网站上的建议,我尝试使用.htaccess重写规则来解决该问题,但由于某种原因,我无法使该规则正常工作。

为了便于阅读,我在这里缩短了网址。我的 WordPress 网站位于/r.info/blogs/th.我安装了网络功能,以便朋友可以在同一站点下写博客,而无需进行第二次安装。不幸的是,他的网站部分的新网址并不是/r.info/blogs/th/st我想要的。我会比较喜欢/r.info/blogs/st

在不丢失数据的情况下移动网站本身似乎非常困难,我已经通过 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>

<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
</IfModule>
<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
        </IfModule>
</FilesMatch>
<FilesMatch "\.(?i:css|js|gif|ico|jpg|jpeg|jpe|png|pdf|swf|ttf|ttc|eot|otf)$">
    <IfModule mod_headers.c>
                Header unset Set-Cookie
        </IfModule>
</FilesMatch>
# 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]
</IfModule>
<Files "wp-config.php">
        Order allow,deny
        Deny from all
</Files>
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]
</IfModule>

# END WordPress

我尝试过RewriteRule ^r.info/blogs/st/$ r.info/blogs/th/st/在文件顶部包含一些简单的内容(也有一个在线引擎)。

我也尝试过,根据 WP.SE 上的建议:

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

但我假设我还没有充分理解该规则实际上在做什么。使用上述内容时,我收到 500 个错误。

答案1

您可以使用以下重写规则:

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

确保此规则之前没有任何规则具有[L]触发选项,因为如果触发,htaccess 将永远不会到达此规则。

相关内容