【问题标题】:Htaccess Redirect WildcardHtaccess 重定向通配符
【发布时间】:2014-01-06 18:10:26
【问题描述】:

我们最近将我们的网站转移到了一个新的 CMS,但我一直在重定向一个目录。

我们的旧 URL 结构是这样的:

/目录/子目录/this-is-the-post/81281/

我想把它重定向到:

/this-is-the-post-81281

当前的 .htaccess 文件

# 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>

RewriteEngine On
RewriteRule ^[^/]+/[^/]+/([^/]+)/([0-9]+)/?$ /$1-$2 [L,R]

#Redirected wildcard /new to forward slash.
 RedirectMatch 301 /new/(.*) /$1

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect http-status-code-301


    【解决方案1】:

    将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^[^/]+/[^/]+/([^/]+)/([0-9]+)/?$ /$1-$2 [L,R]
    
    RewriteRule ^new/(.*)$ /$1 [L,R]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    【讨论】:

    • 没有;没有成功,将在上面发布我的 .htaccess 文件
    • 还要告诉我这个 .htaccess 的位置吗?
    • 网站根目录下
    • 检查您的完整 .htaccess。
    • 这是整个文件
    【解决方案2】:

    我在 .htaccess 重定向中所做的事情

    Redirect permanent /directory/sub-directory/this-is-the-post/81281 http://www.youdomain.com/this-is-the-post-81281
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-04
      • 2018-10-03
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      • 2018-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多