需要用mod_rewrite重写一个特定的链接

时间:2014-10-16 11:05:00

标签: .htaccess mod-rewrite

/ support-category /?category = 类别名称

为:

/ support / category / 类别名称

这似乎不起作用:

RewriteRule ^support/category/$4 support-category/?category=$4 [nc]

谢谢:)

此外,如果我通过/ support / category / category name格式访问链接,那么带有get请求的类别名称是否可行?

这里是整个.hatacces文件夹,它位于网站的根目录中。

AuthName "Restricted Area"
AuthType Basic
AuthUserFile "/var/www/vhosts/xxx.de/dev.xxx.de/.htpasswd"
Require valid-user

# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
        AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
    <IfModule mod_mime.c>
        # DEFLATE by extension
        AddOutputFilter DEFLATE js css htm html xml
    </IfModule>
</IfModule>
# END W3TC Browser Cache
# BEGIN W3TC CDN
<FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css)$">
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
# END W3TC CDN
# BEGIN W3TC Page Cache core
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteRule .* - [E=W3TC_ENC:_gzip]
    RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
    RewriteRule .* - [E=W3TC_PREVIEW:_preview]
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} =""
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
    RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
    RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
</IfModule>
# END W3TC Page Cache core
# 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]
RewriteRule ^support/category/([^/]+)$ support-category/?category=$1 [L,QSA,NC]
</IfModule>

# END WordPress

将此添加到functions.php

function rewrite_support() {
    $wp_rewrite->flush_rules();
    add_rewrite_rule('^support/category/([^/]+)/?$','support-category/?category=$matches[1]','top');
}

add_action( 'init', 'rewrite_support');

感谢

1 个答案:

答案 0 :(得分:0)

您可以使用:

RewriteEngine On

RewriteRule ^support/category/([^/]+)$ support-category/?category=$1 [L,QSA,NC]