得到了一个新的PC,并试图设置我的环境与我以前的环境一样。
根索引加载主页(index.php)
本地主机/根/
联系人-我们没有文件扩展名“文件找不到404重定向”
本地主机/根/联系人-us
contact-us.php如果我添加扩展名.php,就会找到该文件
localhost/root/contact-us.php
其他index.php文件也能正常工作,如
localhost/root/blog/ localhost/root/products/
例如根>博客>索引
但是root > blog >这个新的博客是找不到的。
所有的东西都在网站的直播版上运行,只是不能让我的本地主机工作.
RewriteEngine On
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
# To internally rewrite /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# Redirect to www.
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [L,R=301]
# Redirect HTTP to HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
# Error redirects
ErrorDocument 400 https://www.mywebsite.com/error/bad-request
ErrorDocument 401 https://www.mywebsite.com/error/unauthorised
ErrorDocument 403 https://www.mywebsite.com/error/forbidden
ErrorDocument 404 https://www.mywebsite.com/error/file-not-found
ErrorDocument 500 https://www.mywebsite.com/error/internal-server-error我在我的.htaccess中有上面的代码,用于删除以前在我的旧PC上修复这个问题的.php .
我该怎么做才能让这件事奏效?
发布于 2022-11-15 16:43:23
不知道为什么,但是这个更新的htaccess代码解决了我的问题。
############ LIVE ONLY ############
#
# force WWW
# RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
# RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [L,R=301]
# force HTTP to HTTPS
# RewriteCond %{SERVER_PORT} 80
# RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
#
############ LIVE ONLY ############
RewriteEngine on
# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
# To internally rewrite /dir/file.php to /dir/file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# Error redirects
ErrorDocument 400 https://www.mywebsite.com/error/bad-request
ErrorDocument 401 https://www.mywebsite.com/error/unauthorised
ErrorDocument 403 https://www.mywebsite.com/error/forbidden
ErrorDocument 404 https://www.mywebsite.com/error/file-not-found
ErrorDocument 500 https://www.mywebsite.com/error/internal-server-error我添加了删除尾随斜杠代码,并在本地工作时注释掉了指向www的强制和强制到https请求。
现在我可以用干净的URL查看我所有的页面了。
https://stackoverflow.com/questions/74443703
复制相似问题