找不到htaccess规则返回页面

时间:2018-08-21 10:21:27

标签: .htaccess apache2

我不确定为什么这在我的本地Apache2服务器上不起作用。

当我用http://localhost/v1.0#测试时 它给了我

  

在此服务器上找不到请求的URL /v1.0。阿帕奇/2.4.18   (Ubuntu)位于本地主机端口80的服务器

Options +FollowSymLinks
# Turn off MultiViews https://stackoverflow.com/a/25423722/646732
Options -MultiViews

# Directive to ensure *.rdf files served as appropriate content type,
# if not present in main apache config
AddType application/rdf+xml .rdf
AddType application/rdf+xml .owl
AddType text/turtle .ttl
AddType application/n-triples .n3
AddType application/ld+json .json

# Rewrite engine setup
RewriteEngine On

# code 308 permanent redirect, cacheable,
# The request method and the body will not be altered, 
# whereas 301 may incorrectly sometimes be changed to a GET method.
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308

# flag https://httpd.apache.org/docs/2.4/rewrite/flags.html
# L|last If the rule matches, no further rules will be processed
# NE|noescape Do not convert to hexcode equivalent, i.e. # to %23
# OR Combine rule conditions with a local OR instead of the implicit AND

# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

# make sure we don't have the file or a directory index to serve
# the rest fails to redirect if we do
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

# 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 ^v0.1#(.*)$ https://miranda-zhang.github.io/cloud-computing-schema/v0.1/index.htm#$1 [R=308,NE,L]
RewriteRule ^v1.0#(.*)$ https://miranda-zhang.github.io/cloud-computing-schema/v1.0/index-en.html#$1 [R=308,NE,L]

# Rewrite rule to serve JSON-LD content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} application/ld+json
RewriteRule ^v1.0#$ https://miranda-zhang.github.io/cloud-computing-schema/v1.0/ontology.json [R=308,L]

# Rewrite rule to serve RDF/XML content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} \*/\* [OR]
RewriteCond %{HTTP_ACCEPT} application/rdf\+xml
RewriteRule ^v0.1#$ https://miranda-zhang.github.io/cloud-computing-schema/v0.1/ontology/cocoon.rdf [R=308,L]
RewriteRule ^v1.0#$ https://miranda-zhang.github.io/cloud-computing-schema/v1.0/ontology.xml [R=308,L]

# Rewrite rule to serve N-Triples content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} application/n-triples
RewriteRule ^v1.0#$ https://miranda-zhang.github.io/cloud-computing-schema/v1.0/ontology.nt [R=308,L]

# Rewrite rule to serve TTL content from the vocabulary URI if requested
RewriteCond %{HTTP_ACCEPT} text/turtle [OR]
RewriteCond %{HTTP_ACCEPT} text/\* [OR]
RewriteCond %{HTTP_ACCEPT} \*/turtle
RewriteRule ^v0.1#$ https://miranda-zhang.github.io/cloud-computing-schema/v0.1/ontology/cocoon.ttl [R=308,L]
RewriteRule ^v1.0#$ https://miranda-zhang.github.io/cloud-computing-schema/v1.0/ontology.ttl [R=308,L]

RewriteCond %{HTTP_ACCEPT} .+
RewriteRule ^$ https://miranda-zhang.github.io/cloud-computing-schema/v1.0/406.html [R=406,L]

# Default response
# ---------------------------
# Rewrite rule to serve the RDF/XML content from the vocabulary URI by default
RewriteRule ^$ https://miranda-zhang.github.io/cloud-computing-schema/v1.0/ontology.xml [R=308,L]

那是我的网址中有一个点吗?

旧的.htaccess可以正常工作,我看不到任何明显错误的地方。

1 个答案:

答案 0 :(得分:1)

您无法匹配井号,因为浏览器不会将井号发送到服务器。它仅用于客户端。

相关问题