簡體   English   中英

mod_rewrite無法使用我的網址

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM