【问题标题】:how to configure apache for xampp on mac osx lion to use mod_rewrite如何在 mac osx lion 上为 xampp 配置 apache 以使用 mod_rewrite
【发布时间】:2013-09-27 17:27:04
【问题描述】:
我完全是 .htaccess 或 apache 的新手。不知道它是如何工作的。
我的网址是这样的
http://localhost/category.php?category=something
我想在 category.php 中将变量值作为 something 但想将 url 显示为
http://localhost/something
我该怎么做,请帮忙。
提前谢谢你
【问题讨论】:
标签:
apache
.htaccess
mod-rewrite
url-rewriting
localhost
【解决方案1】:
第一个规则会将丑陋的 URL 重定向到漂亮的 URL,第二个规则将在内部将漂亮的 URL 重定向回来,同时不会改变用户在浏览器 URL 上看到的内容:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Redirect /category.php?category=something to /something
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+category\.php\?category=([^&\s]+) [NC]
RewriteRule ^ /%1? [R=302,L]
# Internally forward /something to /category.php?category=something
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ /category.php?category=$1 [QSA,NC,L]
一旦您确认其按预期工作,请将 R=302 更改为 R=301。