Forum Moderators: phranque
RewriteRule ^old-folder/(.*) http://www.example.com/new-folder/$1 [R=301,L]
Now I have multiple pages going into multiple subfolders. The clue is the string at the end of the page name. For example:
^old-folder/something-clue\.html going to the /old-folder/clue/same-file-name.html
If I have several pages like:
something-clue
something1-clue
something2-clue
...
How to I match that before "-clue"
I tried:
RewriteRule ^old-folder/(.*)clue\.html$ http://www.example.com/old-folder/clue/$1clue.html [R=301,L]
and got infinite loop.
I also tried:
RewriteRule ^old-folder/(.*)clue\.html$ http://www.example.com/old-folder/clue/$1 [R=301,L]
and got a redirect that worked to the point of "clue\.html$" which was missing.
What am I missing?
Thanks
[edited by: jdMorgan at 8:15 pm (utc) on Jan. 15, 2009]
[edit reason] example.com [/edit]
Can either <something> or <clue> (or both) have a hyphen in it? If so, what other characteristics can be used to find the boundary between <something> and <clue>?
Jim
I made initial mistake with "old-folder" idea. This is simpler:
folder/<something-clue>\.html to redirect to /folder/<clue>/<something-clue>.html
where "something" is the variable that is different from file to file while "clue" is identical for each group of files being transferred to the new subfolder.
Serve content for the URL example.com/folder/<something-clue>.html from the file located at /folder/<clue>/<something-clue>.html :
RewriteRule ^folder/([^-]+-([^.]+))\.html$ /folder/$2/$1.html [L]
Jim
[edited by: jdMorgan at 1:52 am (utc) on Jan. 13, 2009]
I tried this:
RewriteRule ^folder/([^.]+)-clue\.html$ /folder/clue/$1-clue.html [L]
and similar, but keep getting into infinite loops.
What is wrong with ([^.]+) or $1 which should correspond to the grouping?
I'm just trying to pick the string which is everything but dot falling between "folder/" and "-clue.html"
That "just" seems to be quite a math for me. Sigh.
Thanks
I wanted to get "([^-]+-clue)" working but could not. I noticed that \w style is not used around much.
The problem was that [^-] means all but hyphen and I needed hyphen included as well.
I tried ([^.]-clue) which did not work. Then I tried ([^.]+-clue) which would create that loop.
What should I use in place of [\w-]*
Thanks
(([^-]+-)+clue)
([^-]+-) means all but hyphen plus hyphen, right?
...and than we just add the famous "clue"?
This should help in using $1 and $2 for folder as per Jim's original suggestion while keeping "clue" hard coded in the first part as a condition since not all pages are moving.
Thanks!
Here is the full line:
RewriteRule ^folder/(([^-]+-)+clue)\.html$ http://www.example.com/folder/clue/$1.html [R=301,L]
The one that works is:
RewriteRule ^folder/([\w-]*clue)\.html$ http://www.example.com/folder/clue/$1.html [R=301,L]
?
Thanks
[edited by: jdMorgan at 8:16 pm (utc) on Jan. 15, 2009]
[edit reason] example.com [/edit]
RewriteRule ^folder/(([^\-/]+-)+clue)\.html$ http://www.example.com/folder/clue/$1.html [R=301,L]
This is because the regular-expressions library used by mod_rewrite comes with the operating system of the server. It isn't part of mod_rewrite, and it isn't part of Apache. So if Apache is running on a Windows OS, then Windows provides the regular-expressions "processor", and if Apache is running on Linux, then the regex functions are provided by the library packaged with Linux. Because of this, support for various regex features can vary independently of Apache itself.
Anyway, feel free to use "[\w-]" if you're sure that you're going to be on the same same server for a long time, or if you feel prepared to modify the code in the future if your hosting set-up changes. I only suggested the modified pattern as being a somewhat more "robust" implementation over time and across hosting platforms.
Jim
[edited by: jdMorgan at 8:14 pm (utc) on Jan. 15, 2009]