我想将www.example.com/guides.html重写为www.example.com/guides
我几乎使用在stackoverflow中找到的每个版本重写了htaccess文件,并且可以使其正常工作。
我目前正在导航至以下网址:
<a href="/guides.html"> GUIDES </a>
如果我在开发服务器中尝试使用:
http://localhost:3000/guides
我知道
“无法获取/指南”。
如果我在生产服务器中尝试它,则会得到:
“内部服务器错误
服务器遇到内部错误或配置错误,并且 无法完成您的请求。
请通过webmaster@example.com与服务器管理员联系,以 告知他们该错误发生的时间以及您的操作 在此错误之前执行。
有关此错误的更多信息可能在服务器错误中可用 日志。>
此外,在遇到500内部服务器错误错误时 尝试使用ErrorDocument处理请求。”
这是我的htaccess文件:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A691200
ExpiresByType image/png A691200
ExpiresByType image/jpeg A691200
ExpiresByType text/css A691200
ExpiresByType text/javascript A691200
ExpiresByType application/javascript A691200
</IfModule>
ErrorDocument 401 "Unauthorized"
ErrorDocument 403 "Forbidden"
<IfModule mod_negotiation.c>
#Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
#### PERSISTENT CONTENT ####
#### PERSISTENT CONTENT END ####
DirectoryIndex index.php index.cgi index.html
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} ^\/(js\/main\.js|css\/(\d+|common|site)\.css)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ sitepro/$1 [L,QSA]
#### PERSISTENT CONTENT ####
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
这是我的修改方式:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A691200
ExpiresByType image/png A691200
ExpiresByType image/jpeg A691200
ExpiresByType text/css A691200
ExpiresByType text/javascript A691200
ExpiresByType application/javascript A691200
</IfModule>
ErrorDocument 401 "Unauthorized"
ErrorDocument 403 "Forbidden"
<IfModule mod_negotiation.c>
#Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
#### PERSISTENT CONTENT ####
#### PERSISTENT CONTENT END ####
DirectoryIndex index.php index.cgi index.html
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_URI} ^\/(js\/main\.js|css\/(\d+|common|site)\.css)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ sitepro/$1 [L,QSA]
#### PERSISTENT CONTENT ####
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
## hide .php extension
RewriteBase /
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ $1 [R=301,L]
答案 0 :(得分:0)
偶然发现我偶然发现一篇文章,提到在编写规则之前需要“选项+多视图”。它现在正在运行,至少对于我的生产服务器而言。