Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.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
Apache 将url从php文件重写到任何虚拟目录_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Apache 将url从php文件重写到任何虚拟目录

Apache 将url从php文件重写到任何虚拟目录,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,我正在努力将文件重写到虚拟目录。我已经在谷歌上搜索了很多,但我尝试的东西对我来说都不管用,所以我的.htaccess的其他部分可能有问题,或者只是与这些规则相冲突 我想要实现什么: Rewrite https://www.domain.com/index.php -> https://www.domain.com/ Rewrite https://www.domain.com/page.php -> https://www.domain.com/any-pagename/ # De

我正在努力将文件重写到虚拟目录。我已经在谷歌上搜索了很多,但我尝试的东西对我来说都不管用,所以我的.htaccess的其他部分可能有问题,或者只是与这些规则相冲突

我想要实现什么:

Rewrite https://www.domain.com/index.php -> https://www.domain.com/
Rewrite https://www.domain.com/page.php -> https://www.domain.com/any-pagename/
# Deflate Compression by MimeType
<IfModule mod_deflate.c>
 <FilesMatch "\.(js|jpg|jpeg|gif|png|css)$">
  ExpiresActive on
  ExpiresDefault "access plus 1 month"
  SetOutputFilter DEFLATE
 </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Here I want to rewrite my https://www.domain.com/index.php
RewriteRule ^/ index.php [L]
Options -Indexes
</IfModule>
我当前的htaccess(http->https和非www到www)和我的第一个目标:

Rewrite https://www.domain.com/index.php -> https://www.domain.com/
Rewrite https://www.domain.com/page.php -> https://www.domain.com/any-pagename/
# Deflate Compression by MimeType
<IfModule mod_deflate.c>
 <FilesMatch "\.(js|jpg|jpeg|gif|png|css)$">
  ExpiresActive on
  ExpiresDefault "access plus 1 month"
  SetOutputFilter DEFLATE
 </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Here I want to rewrite my https://www.domain.com/index.php
RewriteRule ^/ index.php [L]
Options -Indexes
</IfModule>
#通过MimeType压缩
过期于
ExpiresDefault“访问加1个月”
SetOutputFilter放气
重新启动发动机
重写条件%{HTTPS}关闭
#首先重写到HTTPS:
#不要把www.放在这里。如果已经存在,将包括在内,如果没有
#随后的规则将捕获它。
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
#现在,将任何请求重写到错误的域以使用www。
重写cond%{HTTP_HOST}^www\。
重写规则^(.*)$https://www.%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
#在这里我想重写我的https://www.domain.com/index.php
重写规则^/index.php[L]
选项-索引

您上一条规则似乎有问题。将其替换为以下规则:

# Here I want to rewrite my https://www.domain.com/index.php

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

测试了这个。这并没有改变我浏览器地址栏中的某些内容,但它“破坏”了css和图像。我现在只能看到DOM及其内容。销毁是一个相当沉重的词,因为这个糟糕的重写规则,检查chrome开发工具,看看为什么css/js没有加载(这个规则我们忽略了真实的文件和目录)。另外,这不是为了更改浏览器中的URL,它只是将所有内容都死记硬背到当前目录中的
index.php
。未捕获的语法错误:错误是意外标记。这与此重写规则无关。当我删除此htaccess行时,它会再次工作。