我想讓SEO友好的URL使用Apache mod_rewrite。mod_rewrite不能與我的網址一起工作
我正常的網址是這樣的 -
index.php?p=about
index.php?p=contact
index.php?p=this
我期待SEO友好的URL應該是與此類似 -
localhost/php_advance/ch02/about
localhost/php_advance/ch02/contact
localhost/php_advance/ch02/this
我創建一個.htaccess
文件,並做一些改變試了一下到我的apache httpd.conf
文件。
這是我的.htaccess文件
<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Set the base to this directory:
RewriteBase /php_advance/ch02/
# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
</ifModule>
而且也,在httpd.conf
文件的末尾,我加了一些像這樣的代碼 -
<Directory "C:/wamp/www/php_advance/ch02">
AllowOverride All
</Directory>
NOTE:
我使用WAMP服務器和Windows 07
但這種編碼不適合我。希望有人能幫助我。 謝謝。
你得到404嗎? – anubhava
@anubhava,不,我不能得到404。當我在瀏覽器地址欄上輸入'http:// localhost/php_advance/ch02/about'時,我可以得到'Not Found 請求的URL/php_advance/ch02/about在這個服務器上找不到.' – TNK
哦,那就是404 :) – anubhava