how to configure apache for xampp on mac osx lion to use mod_rewrite

笑着哭i 提交于 2019-12-12 03:43:22

问题


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

my url is like

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

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

http://localhost/something

how can i do this please help.

Thank you in advance


回答1:


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]

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



来源:https://stackoverflow.com/questions/18948709/how-to-configure-apache-for-xampp-on-mac-osx-lion-to-use-mod-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!