【发布时间】:2017-03-27 07:59:19
【问题描述】:
我的第一个问题是“我可以使用 html 文件来重写 url 参数并在 javascript 中处理参数吗?”
第二个问题是: 我该怎么办?,如果我想重写这些网址:
*localhost OR sample.com*/blog.html
*localhost OR sample.com*/about.html
*localhost OR sample.com*/articles.html?title=sample-name-parameter
到这些网址:
*localhost or sample.com*/blog/
*localhost or sample.com*/about/
*localhost or sample.com*/articles/sample-name-parameter
这是我的 htaccess 文件:
DirectoryIndex blog.html index.html
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^articles/([^/]+)$ /articles/$1.html?p=$2 [L]
</IfModule>
【问题讨论】:
标签: apache .htaccess mod-rewrite url-rewriting url-parameters