Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Apache Rewrite Rules & Physical Directories |
|
Author |
|
mobilejson
Joined: 02 Sep 2015 Posts: 1 Location: USA, Alexandria
|
Posted: Wed 02 Sep '15 17:21 Post subject: Apache Rewrite Rules & Physical Directories |
|
|
Hi Apache Users,
I'm a newb with apache and could use some help. I'm using per
directory rewrites and delivering files via RDF and HTML using apache
.htaccess.I'm running Apache 2.4.7 on Ubuntu.
Here's my situation:
For content negotiation purposes, I have several independent html & rdf files in a directory named "/verbs/"
For example,
/verbs/answered.html, answered.rdf, answered.jsonld
/verbs/asked.html, asked.rdf, asked.jsonld
I also have a singe representation list of these same verbs, but as
one html named index.html
For example,
/verbs/index.html
I would like to be able to GET both the independent verbs and the
entire list as these various RDF types using Accept header request.
I can currently GET the independent terms (for each IRI) and apache returns the
appropriate content type based on the Accept request
For example,
curl --header "Accept: application/rdf+xml" -L
http://example.com/adl/verbs/answered
Returns an xml representation in RDF.
However, if I attempt to GET the entire list of verbs it ALWAYS
returns HTML. For example,
curl --header "Accept: application/rdf+xml" -L http://example.com/adl/verbs
I have two .htaccess files. One is at the /verbs/ directory level and
one is up a higher directory. The .htaccess at the higher directory is
pasted below.
It appears that my problem is that I have an actual physical directory
with the same name "/verbs/" as my Rewrite rule name ^verbs$. For
example, if I change the rewrite rule name to ^verbset$ my GET
requests work fine and return any of the content types that are
requested.
I would rather not work around this by naming the rewrite rule name,
and would prefer to learn more about apache instead of trying to apply
dated linked data recipes. Are there any specific directives that
might be causing this conflict? Or is it a limitation that rewrite
rule names can't be the same name as physical directories on the
server? Thanks in advance for any advice or resources!
# Turn off MultiViews
Options -MultiViews
# Rewrite engine setup
RewriteEngine On
# Directive to allow Cross origin requests
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType text/html .html
AddType application/rdf+xml .rdf
AddType text/turtle .ttl
AddType application/ld+json .jsonld
RewriteBase /
# Rewrite rule to serve HTML content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT}
!application/rdf\+xml.*(text/html|application/xhtml\+xml)
RewriteCond %{HTTP_ACCEPT} text/html [OR]
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.*
RewriteRule ^verbs$ http://example.com/adl/verbs/index.html [R=303]
# Rewrite rule to serve RDF/XML content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^verbs$ http://example.com/adl/verbs.rdf [R=303]
# Rewrite rule to serve Turtle content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} text/turtle
RewriteRule ^verbs$ http://example.com/adl/verbs.ttl [R=303]
# Rewrite rule to serve JSON-LD content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} application/ld\+json
RewriteRule ^verbs$ http://example.com/adl/verbs.jsonld [R=303]
# Choose the default response
# ---------------------------
# Rewrite rule to serve the RDF/XML content from the vocabulary URI by default
RewriteRule ^verbs$ http://example.com/adl/verbs/index.html [R=303] |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
|
Back to top |
|
|
|
|
|
|