I want to shorten my owncloud caldav and carddav urls.
currently the urls are :
https://site.mysite.com/owncloud/remote.php/caldav/principals/edison/
https://site.mysite.com/owncloud/remote.php/carddav/addressbooks/edison/contacts
Note : The name edison and what ever follows after that is dynamic it will change depending on the users.
I want it to be
https://site.mysite.com/caldav/principals/edison/
https://site.mysite.com/carddav/addressbooks/edison/contacts
.htaccess file contains
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !\.sso/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Eg:
If the user request for https://site.mysite.com/caldav/principals/edison/ . Then it should redirect to https://site.mysite.com/owncloud/remote.php/caldav/principals/edison/
How can it be done using mod_rewrite ?
mod_rewrite Prepend Path to Requested URL with Dynamic Portion
Starting at server root, enter the requested URL path in the RewriteRule
"pattern" parameter, and the desired path in the "substitution" parameter. In the form:
RewriteRule pattern substitution [flags]
In this case:
RewriteRule ^caldav/principals/edison/$ owncloud/remote.php/caldav/principals/edison/ [L]
If a portion of the URL (between slashes) varies and you don't want to (or can't) write a rule for every situation then use the regular expression ([^/]+)
to capture the dynamic portion and inject it into your substituted path using the RE capture variable $1
:
RewriteRule ^caldav/principals/([^/]+)/$ owncloud/remote.php/caldav/principals/$1/ [L]
The first set of parenthesis is $1
, the second set is $2
, etc. And capturing parenthesis can be nested.
Put the more specific rules higher in the rules list, and more general rules lower in the list. So I suggest putting this rule first, right after RewriteBase /
.
来源:https://stackoverflow.com/questions/28948418/mod-rewirte-for-caldav-and-carddav-urls-in-owncloud