Apache Rewrite Rules

28 views
Skip to first unread message

Alpesh Bhavsar

unread,
Nov 2, 2012, 2:20:04 AM11/2/12
to vg...@googlegroups.com
Hi All,

I need help to create apache rewrite rule. My requirement is as given below.




Note: Above requirement is not for static URL, but there would be any other word instead of "directory" and "file_name_1". 

- "directory" word should be removed in new redirected URL
- underscore ( _ ) should be replaced with Hyphen ( - )
- "file-name-1" should be ended with .html extension.

I appreciate your reply.

Thank you.
Alpesh Bhavsar


Alpesh Bhavsar

unread,
Nov 2, 2012, 3:45:23 AM11/2/12
to vg...@googlegroups.com
Hi All,

Its done. I have applied below rules.

        RewriteCond     %{REQUEST_URI}  ^/(.*)/([^_]*)_(.*)$
        RewriteRule ^(/?.*/[^/]*?)_([^/]*?_[^/]*)$ $1-$2      [N]
        RewriteRule ^(/?.*/[^/]*?)_([^/_]*)$ $1-$2.html      [R=301]
        RewriteRule ^/(.*)/(.*)$        $2                           [R,L]

ElectroMech

unread,
Nov 6, 2012, 12:13:40 AM11/6/12
to vg...@googlegroups.com
Hi,

I appreciate, it is always a good practice to post the solution to group.

On Fri, Nov 2, 2012 at 1:15 PM, Alpesh Bhavsar <alpeshbha...@gmail.com> wrote:
Hi All,

Its done. I have applied below rules.

        RewriteCond     %{REQUEST_URI}  ^/(.*)/([^_]*)_(.*)$
        RewriteRule ^(/?.*/[^/]*?)_([^/]*?_[^/]*)$ $1-$2      [N]
        RewriteRule ^(/?.*/[^/]*?)_([^/_]*)$ $1-$2.html      [R=301]
        RewriteRule ^/(.*)/(.*)$        $2                           [R,L]


I suggest other to follow the same, post the final solution and conclusion, will help to the community.

 
Thanks and Regards.
--
--
Nilesh Vaghela
(RHCSA RHCE)
ElectroMech Corporation
Redhat Channel Partner and Training Partner
302, New York Plaza, Opp Judges Bunglow, Bodakdev, Ahmedabad
22, 1st Floor, Vardhaman Complex, Subhanpura , Baroda.
www.electromech.info

Reply all
Reply to author
Forward
0 new messages