Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何只允许用户重写页面?_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex 如何只允许用户重写页面?

Regex 如何只允许用户重写页面?,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我有一个网站,在那里我使用SSI,包括一些东西的头版。但是,我想向用户显示一个以.html结尾的URL。我通过.htaccess和mod_rewrite重定向完成了这一点 RewriteRule ^index\.html$ index.shtml [PT,L] 另外,我正在使用指向此URL的另一个重定向来在页面内部加载JavaScript内容(example.html到index.html#example.html),条件是不重定向index.html) 现在,我想禁止.shtml页面403。

我有一个网站,在那里我使用SSI,包括一些东西的头版。但是,我想向用户显示一个以
.html
结尾的URL。我通过
.htaccess
mod_rewrite
重定向完成了这一点

RewriteRule ^index\.html$ index.shtml [PT,L]
另外,我正在使用指向此URL的另一个重定向来在页面内部加载JavaScript内容(
example.html
index.html#example.html
),条件是不重定向
index.html

现在,我想禁止
.shtml
页面
403
。这也很容易:

RewriteRule ^index\.shtml - [F]
但是,现在
index.html
也被禁止了

我已尝试将
L
添加到
.html
-to-
.shtml
规则中,但这没有帮助。这个问题怎么解决

编辑:这是我完整的
.htaccess
文件,其中包含anubhava建议的内容

ErrorDocument 404 /subdir/notfound.html
ErrorDocument 500 /subdir/internalerror.html

RewriteEngine on
RewriteCond $1 !^(index\.html|notfound\.html|internalerror\.html)(#.*)?$
RewriteRule ^([^/]*\.html)$ /subdir/index.html#$1 [R=302,NE]

RewriteRule ^index\.html$ index.shtml [PT,L]

RewriteCond %{THE_REQUEST} index\.shtml
RewriteRule ^index\.shtml - [F]
和我的目录结构:

/public_html
|
+-- subdir
    |
    +-- .htaccess
    |
    +-- index.shtml
    |
    +-- notfound.html
    |
    +-- internalerror.html
    |
    +-- style.css
    |
    +-- script.js
    |
    +-- ajax-pages
        |
        +-- index.html
        |
        +-- foo.html
        |
        +-- bar.html

您可以将此规则用于
请求变量

RewriteCond %{THE_REQUEST} /index\.shtml [NC]
RewriteRule ^ - [F]
您的规则的问题是,
index.html
被重写为
index.shtml
,Apache重新注入重写的URI以进行进一步的规则评估,Apache也为
index.html
发出禁止的错误

完成。htaccess:

ErrorDocument 404 /subdir/notfound.html
ErrorDocument 500 /subdir/internalerror.html

RewriteEngine on

RewriteCond %{THE_REQUEST} index\.shtml [NC]
RewriteRule ^index\.shtml - [F]

RewriteRule ^index\.html$ index.shtml [L,NC]

RewriteCond %{REQUEST_URI} !/(index\.s?html|notfound\.html|internalerror\.html) [NC]
RewriteRule ^([^/]*\.html)$ /subdir/index.html#$1 [R=302,NE,L]

是的,但是
L
不应该意味着URL不再被重写吗?不,这不正确
L
只是将URI注入回规则求值。好的。还有一个问题。如果文件位于子目录(我的案例)中,则此操作不起作用。
RewriteCond%{the_REQUEST}/index\.shtml[NC]
甚至可以在子目录中工作。你能发布你的完整的.htaccess吗?这样我就可以调查并提出建议。你能提供一些关于SSI问题的细节吗。这是如何做到的,你面临什么问题?