如何在Mac OS X Lion上为Xampp配置Apache以使用mod_rewrite [英] how to configure apache for xampp on mac osx lion to use mod_rewrite

查看:58
本文介绍了如何在Mac OS X Lion上为Xampp配置Apache以使用mod_rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全是.htaccess或apache的新手.不知道它是如何工作的.

i am totally newbie for .htaccess or apache. Don't know how it works.

我的网址就像

http://localhost/category.php?category=something

我想在category.php中获取变量值为 something ,但希望将网址显示为

i wanna get the variable value as something in category.php but wanna show the url as

http://localhost/something

我该怎么做,请帮忙.

提前谢谢

推荐答案

第一个规则会将丑陋的URL重定向到漂亮的URL,第二个规则将在内部将漂亮的URL重定向回,而不会更改用户在浏览器URL上看到的内容:

First rule will redirect the ugly URL to the pretty URL, second rule will internally redirect the pretty URL back while not changing what the user see on the browser 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.

Once you confirm its working as expected change R=302 to R=301.

这篇关于如何在Mac OS X Lion上为Xampp配置Apache以使用mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆