【发布时间】:2015-12-25 06:07:37
【问题描述】:
我有一个重写规则来制作漂亮的 url,但它也重写 css、js 和其他文件。
我想重写
http://localhost/example/post/?postid=af1ub4zu4y&title=this-is-the-first-post.html
到
http://localhost/example/post/af1ub4zu4y/this-is-the-first-post.html
我正在尝试这种方式
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^post/([^/]*)/(.*\.html) /example/post/?postid=$1&title=$2 [QSA,L,B]
也试过这样的
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^post/([^/]*)/(.*\.html) /example/post/?postid=$1&title=$2 [QSA,L,B]
和
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^.*\.(css|jpe?g|gif|png|js|ico)$ [NC]
RewriteRule ^post/([^/]*)/(.*\.html) /example/post/?postid=$1&title=$2 [QSA,L,B]
但是这些解决方案都不适合我。请查看并提出任何可行的方法。
【问题讨论】:
-
你想重写什么?提供样品。另外,请确认htaccess是否正在加载; mod-rewrite 已启用等,
-
@hjpotter92 请看更新,htaccess 已加载,mod-rewrite 已启用
-
是的,我收到 404 错误
-
@TallboY 我将删除下面的回复,因为您可能会对这两种方法感到困惑。
-
@hjpotter92 我没有感到困惑,我一次尝试一种解决方案,无论如何感谢您花时间提供帮助
标签: apache .htaccess mod-rewrite url-rewriting friendly-url