我有一个.htaccess文件,它将所有URL重写path/to/file.php
为path/to/file
。
我曾在WAMP上本地工作,也曾在blacknight托管的域上工作。
但是,我们正在使用Debian 9迁移到Google Cloud Platform,它根本不能在这里使用。如果我不包括.php扩展名,则会收到404错误。
以下是我完整的.htaccess文件:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^post/([^\/]+)/?$ post.php?url=$1 [L,NC,QSA]
RewriteRule ^payment/([^\/]+)/?$ payment.php?sub=$1 [L,NC,QSA]
RewriteRule ^player/([^\/]+)/?$ player.php?id=$1 [L,NC,QSA]
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 week"
ExpiresByType image/jpeg "access 1 week"
ExpiresByType image/gif "access 1 week"
ExpiresByType image/png "access 1 week"
ExpiresByType text/css "access 1 hour"
ExpiresByType text/x-javascript "access 1 hour"
</IfModule>
<IfModule mod_headers.c>
Header set Connection keep-alive
<filesmatch "\.(ico|gif|jpg|jpeg|png)$">
Header set Cache-Control "max-age=604800, public"
</filesmatch>
<filesmatch "\.(css)$">
Header set Cache-Control "max-age=3600, private"
</filesmatch>
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=3600, private"
</filesmatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=0, private, must-revalidate"
</filesMatch>
</IfModule>
我该怎么办才能解决此问题,或者还有另一种方法可以在Google Cloud Platform中重写URL?
如果您的Apache服务器已启用,则应检查AllowOverride指令是否也已启用(设置为“全部”或允许使用特定选项)。否则,Apache将不会考虑您放置在其中的指令。
通常应将其放置在虚拟服务器配置文件或主配置文件中。
这是一个例子:
<Directory "/path/from/where/you/serve/files">
AllowOverride All
</Directory>
更多信息:https : //httpd.apache.org/docs/2.4/mod/core.html#allowoverride
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句