【问题标题】:htaccess rules return page not foundhtaccess 规则返回页面未找到
【发布时间】:2019-01-27 12:23:12
【问题描述】:

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

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

在此服务器上找不到请求的 URL /v1.0。阿帕奇/2.4.18 (Ubuntu) 服务器在 localhost 端口 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 有效,我看不出有什么明显的错误。

【问题讨论】:

  • RewriteRule ^v1.0#$ 应该变成RewriteRule ^v1\.0/?$

标签: .htaccess apache2


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2012-05-11
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2012-08-12
    • 1970-01-01
    • 2020-04-17
    • 2017-12-21
    • 1970-01-01
    相关资源
    最近更新 更多