0

I searched through internet but found no matching question or post. I spent nights on unsuccessful attempts in getting it to work. I would really appreciate if someone could help and give pointers to get this advanced mod_rewrite working. (You may want to jump to The Problem directly below.)

Environment: I have installed websvn latest version on Apache 2.x with MultiView feature which generates URLs in below format without help of any rewrite rules:

https://svnweb.hostname.com/wsvn/Group.Repname/path/to/files/and/folders/in/svn/

Here the "Group" is nothing but SVNParentPath and "Repname" is actual SVN repository. Please note the "." between Group and Repname.

I have SVN 1.7 + Apache 2 configured and below is the URL format:

https://svn.hostname.com/Group/Repname/path/to/files/and/folders/in/svn/

The problem has nothing to do with this SVN URLs. To limit and manage user access to SVN repositories I have configured LDAP auth and LDAP Group based access for each Repname. This configuration is done automatically with help of scripts created by me.

The Requirement/Problem: I want to get /wsn/Group.Repname/ converted to /Group/Repname/ in URL where WEBSVN is using MultiView apache feature to construct its urls.

If you look closely, "Group" and "Repname" are not separate folders in WEBSVN URL and do not match with SVN URL path for repository. I would like to use same svn.hostname.com LDAP auth and LDAP group based permissions used for each Repname for svnweb.hostname.com. To make it work svnweb URL must be matching with SVN server URL like

This: https://svnweb.hostname.com/Group/Repname/path/to/files/and/folders/in/svn/

and not https://svnweb.hostname.com/wsvn/Group.Repname/path/to/files/and/folders/in/svn/

Possible Solution and Limitations: To achieve/fix this, i do not want to modify web application or create new apache LDAP auth and LDAP group configuration supporting "Group.Repname" in path. Imagine over 500+ SVN repositories and the maintenance overhead. I think mod_rewrite can help me to achieve the rewritten URL for me and secure WEBSVN making sure people get access to what they are supposed to access.

I tried several options with rewrite but i could not get /wsn/Group.Repname/ converted to /Group/Repname/. Please let me know if you have any idea how this can be achieved using rewrite. Thanks for reading through, I appreciate your comments and suggestions.

Satish
  • 1
  • 4
  • Is svnweb.hostname.com different than svn.hostname.com? – Jon Lin May 31 '12 at 16:10
  • two different servers. I have rewrite rule on svn.hostname.com that redirects users to svnweb.hostname.com if the access the URL in browser and not in SVN client. – Satish May 31 '12 at 18:50
  • I mentioned about SVN to explain the environment and justify why i am not happy with Group.Repname format of WebSVN. – Satish May 31 '12 at 18:59

2 Answers2

0

Try the following:

RewriteEngine On
RewriteBase /
RewriteRule ^wsvn/([^./]+)\.(.+)$ https://svnweb.hostname.com/$1/$2 [L,NC]

[^./]+ means "more then one sign, but not a point or a slash", .+ means "more than one sign". You might want to add R=301 after NC if the redirect should be permanent.

Christopher
  • 2,005
  • 3
  • 24
  • 50
  • I just tried it with below config (i hope i am doing it correctly). `RewriteEngine on` `RewriteBase /` `RewriteRule ^wsvn/([^.]+)\.([^.]+)/$ /$1/$2 [L,NC, R=301]` I reloaded apache config and tried to access https://svnweb.hostname.com/Group/Repname/ and it gave 404. Apache Logs just say the same - 404. With that rewrite rule I am expecting https://svnweb.hostname.com/wsvn/Group.Repname/ to be converted as https://svnweb.hostname.com/Group/Repname/. – Satish May 31 '12 at 18:51
  • I am afraid! that did not work :(. Apache gives some PHP fatal error in template.php for path of template. Note that MultiViews feature is being used by websvn to construct its urls. websvn php files are in webroot folder. This is really challenging and driving me nuts, never before! If you want i can bundle configuration + websvn to try it out on your apache server. Size will be approx 3MB. – Satish May 31 '12 at 20:02
  • @Satish Maybe that's a good idea - this seems to be more difficult than I thought (and I have to admit that I'm not an expert in using mod_rewrite), so this would give me the possibility to try it by myself. – Christopher May 31 '12 at 20:08
  • i have uploaded it at `http://satishweb.com/share/test.tar.gz`. Size is just under 1 MB. i have configured it assuming that you will extract it inside `/opt`. websvn config file is `/opt/test/html/include/config.php`. Apache config is `/opt/test/conf/vhost.conf`. With multiview on, websvn should construct URLs that i mentioned. I have created sample svn repo for your for testing inside `/opt/test/svn/`. – Satish May 31 '12 at 20:35
  • I really appreciate your time and interest in this, trust me after finding the solution we both will be very satisfied technically lol.. If i want i can ask a php developer to dig into websvn code and make websvn construct URLs the way i want but that would be last option. – Satish May 31 '12 at 20:48
  • I downloaded it, I'll try to find a solution tomorrow! – Christopher May 31 '12 at 21:01
  • Please read my discussion with Ansari on the same page here. :) – Satish May 31 '12 at 22:41
0

Try this rule?

RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^wsvn(\.php)?/(.*?)\.(.*) $2/$3 [L,NC,QSA]

Did you want to change the domain as well? I didn't understand that from your question.

** EDIT **:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/wsvn
RewriteRule ^(.*)/(.*)$ wsvn.php/$1.$2 [L]
Ansari
  • 8,168
  • 2
  • 23
  • 34
  • lets assume that i have only one domain. I tried your rewrite rule but it got into redirect loop. :( Its not that easy it looks like. WebSVN is using MultiView feature of apache to construct its urls. may be you want to try it out on your apache server? search for test.tar.gz on this page and read that comment :) – Satish May 31 '12 at 21:36
  • Try with the RewriteCond? I'll reproduce it in my environment once the simpler things are ruled out. – Ansari May 31 '12 at 21:38
  • I had tried that rewrite condition earlier. It goes in redirect loop. – Satish May 31 '12 at 21:44
  • with redirect loop this is what is see in URL: /wsvn/wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.... to enable rewrite log, i need to prepare test VM and configure it. allow me 15 mins to do do that and get back to you :) – Satish May 31 '12 at 21:56
  • Ohh there's something else going on here then. Are there more rewrite rules? Who's adding on the wsvn.php thing? It's not the rules above ... the logs will definitely help. – Ansari May 31 '12 at 22:00
  • Hmm this doesn't explain why wsvn.php is being written over and over - also this is trying to match against `wsvn.php/test1.T1Repo1` - so the rewrite rules aren't even taking effect. So perhaps the bug is elsewhere? – Ansari May 31 '12 at 22:13
  • There are other rewrite rules for SSL virtualhosts. You can view those rules at http://www.satishweb.com/share/mssl.txt. I will create the exactly same environment on test server and then try those rules to grab rewrite logs. – Satish May 31 '12 at 22:14
  • the rewrite logs that you just saw were on fresh lampp server with websvn installed at root in htdocs. WebSVN is using multiviews feature of apache to construct URLs like /wsvn/test1.T1Repo1/ instead of normal listing.php?repname=test1.T1Repo1&path=%2Fbranches. I want /wsvn/test1.T1Repo1/ to become as /test1/T1Repo1/. Its possible that MultiViews and mod_rewrite not willing to work together? – Satish May 31 '12 at 22:17
  • The rule in point 5 of your vhost rules is never applied because of an extraneous slash. Try `RewriteRule ^(.*)$ %1/$1 [E=VHOST:${lowercase:%{HTTP_HOST}}]` instead. – Ansari May 31 '12 at 22:19
  • Just edited my rule to allow for MultiViews rewriting wsvn to wsvn.php . Can you check now? – Ansari May 31 '12 at 22:23
  • ohh yes! its apache 2 so it makes sense removing slash or "?" should be added after it. However situation is the same. Just to explain more on that. If i access websvn normally it works, urls are like /wsvn/test1/T1Repo1/branches/ but if i type URL that i am looking for /test1/T1Repo1/ it goes in loop and at the end i see this URL: https://hostname.com/wsvn/wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.wsvn.php.test1.T1Repo1/. – Satish May 31 '12 at 22:39
  • Not sure whats wrong, were you able to reproduce this at your test system? even on test server without SSL multihost rewrite rules i get same results. – Satish May 31 '12 at 22:39
  • Can you confirm what URL you are able to access WebSVN by? And then clearly what you would like to access them by? I have a feeling I'm thinking of them backwards. – Ansari May 31 '12 at 22:42
  • lets keep multi ssl off for now. on my test server i have deployed content of test.tar.gz with lampp 1.7.7. I did not use vhost.conf from test.tar.gz, just updated Options to have MultiViews in httpd.conf. i copied your rewrite rules in .htaccess in htdocs where wsvn is deployed. When i visit the websvn website, it still showing urls like /wsvn/test1/T1Repo1/branches/ and when i try to access /test1/T1Repo1/ it goes in redirect loop. I think something is happening between multiviews and rewrite. – Satish May 31 '12 at 22:47
  • I just updated my rule - I assume that the WebSVN URL that works has a dot in it? Like `/wsvn/test1.T1Repo1/branches`? – Ansari May 31 '12 at 22:48
  • yes, thats true and i dont want that. i want `/wsvn/test1.T1Repo1/branches/.....` to be converted as `/test1/T1Repo1/branches/.....` Once it happens, it will match with the svn server URL pattern and i will be able to use the same access rules as SVN server for websvn. – Satish May 31 '12 at 22:50
  • Also your terminology is backwards - what you mean to do is convert /test1/T1Repo1 to /wsvn.php/test1.T1Repo1 - the input to mod_rewrite is the first, and you want the second to be output so that your websvn can interpret it. – Ansari May 31 '12 at 22:55
  • Normal wsvn URL worked but when i tried to access the desired URL i got this -> Fatal error: Call to a member function getTemplatePath() on a non-object in /opt/lampp/htdocs/include/template.php on line 273. 1. when i access wsvn normally, it should automatically use `/test1/T1Repo1/` instead of `/wsvn/test1.T1Repo1/`. 2. I am okay if multiviews is disabled and normal urls like `listing.php?repname=test1.T1Repo1&path=%2Fbranches` get converted to `/test1/T1Repo1/listing/%2Fbranches` I tried some rewrite without multiviews but it broke the wsvn template links to css files and image files. – Satish May 31 '12 at 23:01
  • i do not want to convert /test1/T1Repo1/ to /wsvn.php/test1.T1Repo1/ i want opposite of it. My SVN server URLs are: svn.hostname.com/test1/T1Repo1/ and my needs is that websvn also have the same pattern, that is svnweb.hostname.com/test1/T1Repo1/ – Satish May 31 '12 at 23:03
  • Note: when i say converted "from" "to" that means i am referring to URL in the browser. – Satish May 31 '12 at 23:05
  • its another night on this, its 5AM here. I have to go to bed now or else tomorrow's day will be called as holiday lol. thanks buddy for your valuable time, i am sure will get some solution to this soon.. its been 3 days in row now.. let me know if you get it working with multiviews or without. at the end it has to match with svn server URL pattern which is `svn.hostname.com/test1/T1Repo1/` – Satish May 31 '12 at 23:12
  • Yes you have the right terminology then, never mind and sorry. Let me think. – Ansari May 31 '12 at 23:12