mod_rewrite无法使用我的url


mod_rewrite is not working with my urls

我正在尝试使用apachemod_rewrite制作SEO友好的URL。

我的普通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>