Domanda

We have recently transferred our site to a new CMS and I am stuck on redirecting one directory.

Our old URL structure was this:

/directory/sub-directory/this-is-the-post/81281/

I want to redirect it to:

/this-is-the-post-81281

Current .htaccess file

# 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
È stato utile?

Soluzione

Put this code in your DOCUMENT_ROOT/.htaccess file:

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

Altri suggerimenti

What I did in our .htaccess redirects

Redirect permanent /directory/sub-directory/this-is-the-post/81281 http://www.youdomain.com/this-is-the-post-81281
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top