Eoin OSullivan
asked on
htaccess Rule to redirect and rewrite html links
We have a problem trying to create a htaccess rule
On the webserver we have the following URLs
http://www.domain.com/file.html/test/value/page.html
http://www.domain.com/file.html/test/value/page.html/value/two
We need a redirect URL to change the URL to find the last .html file in the path and redirect to the following
http://www.domain.com/page.html
http://www.domain.com/page.html/value/two
We also need to then Redirect the second URL for codeigniter
http://www.domain.com/index.php/controller/view/page/value/two
The problem is that the RegEx rules are difficult to compile and hard to test in htaccess.
Can someone help and provide the rules or a clear guidance as we are swamped with (!*./\$ variables.
Thank you
On the webserver we have the following URLs
http://www.domain.com/file.html/test/value/page.html
http://www.domain.com/file.html/test/value/page.html/value/two
We need a redirect URL to change the URL to find the last .html file in the path and redirect to the following
http://www.domain.com/page.html
http://www.domain.com/page.html/value/two
We also need to then Redirect the second URL for codeigniter
http://www.domain.com/index.php/controller/view/page/value/two
The problem is that the RegEx rules are difficult to compile and hard to test in htaccess.
Can someone help and provide the rules or a clear guidance as we are swamped with (!*./\$ variables.
Thank you
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you describe the conditions necessary for the 2nd URL to be redirected for codeigniter?
ASKER
Thanks for contributions. To clarify ... The filename will vary but it will always be a .HTML file.
The issue is that the website has local HTML links but is running on codeigniter.
The 2nd rule is to then rewrite the HTML link into a codeigniter formatted URL.
The issue is that the website has local HTML links but is running on codeigniter.
The 2nd rule is to then rewrite the HTML link into a codeigniter formatted URL.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HackneyCab - the bit of the URL between the 2 HTML files will vary so we cannot assume it will be "test/value". Am I right in thinking that finding the last .HTML file in a URL is not easy to do in htaccess.
Well, so long as there will only ever be two fake directories (test and value, for example) then you could replace /test/value/ with /[a-z]+/[a-z]+/ (or something similar if anything other than lowercase alphabetic characters can appear.
Matching variable patterns works fine using regex until you say "the path length/depth can be variable". Then you're in trouble, because regex doesn't offer a way to capture a variable number of sub-patterns.
Matching variable patterns works fine using regex until you say "the path length/depth can be variable". Then you're in trouble, because regex doesn't offer a way to capture a variable number of sub-patterns.
RewriteEngine on
RewriteRule ^file\.html.*?([^/]*\.html