aye
aye

Reputation: 293

htaccess to redirect both folder and file name

I have a file in a folder like this folder1/folder2/folder3/filename.htm. I also have another file like this folder1/folder2/folder3-filename.htm. When i browse the url mysite.com/folder1/folder2/folder3/filename.htm, i want the folder3-filename.htm will be served (displayed)

I know some basics about file name rewrite rules, but i have not seen any mixed-up combination of folder name and file name in that way.

Could anyone help me how to do it?

Upvotes: 1

Views: 289

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270677

Using the expression [^/]+ to match all characters up to but not including the the next / and then .+ to match everything after the last /, the following will work:

RewriteEngine On
RewriteRule ^folder1/folder2/([^/]+)/(.+)$ folder1/folder2/$1-$2 [L]

Upvotes: 1

Related Questions