htaccess RewriteRule 强制将 s 放入 url
htaccess RewriteRule force to put s in the url
htaccess 文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ .html [NC,L]
RewriteRule ^member member.html [NC,L]
RewriteRule member/(.*)/(.*)$ member.html?a=&b=
所以应该像 https://example.com/member/query_1/query_2
问题是这个 link 将无法工作,除非我在 url
中的成员词末尾添加 (s) 个字符
所以工作 link 是 https://example.com/members/query_1/query_2
除非它return我404错误
它在 xamp localhost 中工作正常,但是当我上传到服务器时,我遇到了这个问题。
您可以在站点根目录 .htaccess 中使用此代码:
Options -MultiViews
RewriteEngine On
RewriteRule ^member/?$ member.html [NC,L]
RewriteRule member/([^/]+)/([^/]+)/?$ member.html?a=&b= [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ .html [L]
Options -MultiViews
将关闭内容协商服务。选项 MultiViews
(参见 http://httpd.apache.org/docs/2.4/content-negotiation.html)由 Apache's content negotiation module
使用,它在 mod_rewrite
之前运行 并使 Apache 服务器匹配文件的扩展名。因此,如果 /file
是 URL 那么 Apache 将提供 /file.html
.
htaccess 文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ .html [NC,L]
RewriteRule ^member member.html [NC,L]
RewriteRule member/(.*)/(.*)$ member.html?a=&b=
所以应该像 https://example.com/member/query_1/query_2
问题是这个 link 将无法工作,除非我在 url
中的成员词末尾添加 (s) 个字符所以工作 link 是 https://example.com/members/query_1/query_2
除非它return我404错误 它在 xamp localhost 中工作正常,但是当我上传到服务器时,我遇到了这个问题。
您可以在站点根目录 .htaccess 中使用此代码:
Options -MultiViews
RewriteEngine On
RewriteRule ^member/?$ member.html [NC,L]
RewriteRule member/([^/]+)/([^/]+)/?$ member.html?a=&b= [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ .html [L]
Options -MultiViews
将关闭内容协商服务。选项 MultiViews
(参见 http://httpd.apache.org/docs/2.4/content-negotiation.html)由 Apache's content negotiation module
使用,它在 mod_rewrite
之前运行 并使 Apache 服务器匹配文件的扩展名。因此,如果 /file
是 URL 那么 Apache 将提供 /file.html
.