搜尋此網誌

2013年7月9日 星期二

如何啟用.htaccess的rewrite功能

1. 修改httpd.conf

找到
# LoadModule rewrite_module modules/mod_rewrite.so
把#號去掉
LoadModule rewrite_module modules/mod_rewrite.so

2. 修改httpd-vdirectory.conf

Alias /sign/ "D:/WAMP/htdocs/sign_up/"

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
# Prevent .htaccess and .htpasswd files from being viewed by Web clients.

Require all denied



3. 修改.htaccess

RewriteEngine On
RewriteBase /sign/
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)-(.*).html index.php?routing=$1&action=$2 [L,QSA,NC]

紅色粗體字為關鍵部分!
特別是如果你出現
Not Found
The requested URL /WAMP/htdocs/sign_up/index.php was not found
這種訊息時,關鍵就在於沒有設定RewriteBase!!!