简体   繁体   中英

URL rewrite using Regular expression

I'm using a software tool to create some 301 Redirects Rules for my Joomla site. Example:
From

http://myhost/directory/category/article

to

http://myhost/directory/main-category/category/article

In practice I add the "main-category" to the URL. By specifying the full URL, redirect happens correctly. For example:

Source URL: ^/temp/clustering/cluster-example
Destination URL: http://localhost/temp/main-category/clustering/cluster-example

However I'd like to use Regular expressions to avoid creating a Redirect for every page. I'd need something like:

Source URL: ^/temp/clustering/*
Destination URL: http://localhost/temp/main-category/clustering/???????

I need a regular expression instead of "??????" which places the last element of the path there (In my case it's "cluster-example". As far as I know, this engine uses MySQL implementation of regular expressions
Any help would be highly appreciated!

Place this rule as very first rule in your /temp/.htaccess :

RewriteEngine On
RewriteBase /temp/

RewriteRule ^(clustering/.+)$ main-category/$1 [L,NC,R=301,NE]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM