[英]mod_rewrite is not working with my urls
我正在嘗試使用apache mod_rewrite創建SEO友好的URL。
我的普通網址是這樣的-
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
但是這種編碼對我不起作用。 希望有人能幫助我。 謝謝。
確保已打開mod_rewrite。 在您的httpd.conf文件中,您應具有類似於以下內容的內容:
LoadModule rewrite_module modules/mod_rewrite.so
然后,確保您的htaccess文件位於/ch02/
目錄中。
嘗試這個:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /php_advance/ch02/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /php_advance/ch02/index.php [L]
</IfModule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.