简体   繁体   中英

apache 2.4 module rewrite error

trying to generate dynamic Urls using Module rewrite , it seems like m doing something wrong and getting Server error! server encountered an internal error i used this code

<IfModule mod_rewrite.c>
 #Enable mod_Rewrite
 RewriteEngine on
 RewriteBase /project
 RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html?)\ HTTP
 RewriteRule ^(.*)index\.(php|html?)$ $1 [R=301,L]
 </ifModule>

the project is aliased to C:/project any pointers to achieve what m trying to?? m using apche 2.4 should the .htacess be saved in project folder ?? or conf folder ?? i want to achieve something like this

localhost/project/index.php?departmentId=2/
localhost/project/science-d2/

both should load same page

You are using an infinite loop, like this: Suppose that your apache is configured like this in some config file:

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml

Your rewrite rule may result in:

/project/index.php => /project => /project/index.php => /project => ...

In this case, you've no need of rewrite. So the solution here is comment out all the instructions:

#<IfModule mod_rewrite.c>
# #Enable mod_Rewrite
# RewriteEngine on
# RewriteBase /project
# RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html?)\ HTTP
# RewriteRule ^(.*)index\.(php|html?)$ $1 [R=301,L]
#</ifModule>

Since you are using Apache 2.4 try to replace <IfModule mod_rewrite.c> with <IfModule rewrite_module>

So the final code looks like this:

<IfModule rewrite_module>
    #Enable mod_Rewrite
    RewriteEngine on
    RewriteBase /project
    RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html?)\ HTTP
    RewriteRule ^(.*)index\.(php|html?)$ $1 [R=301,L]
</ifModule>

Of course make sure you comment out rewrite_module in .conf file so it is indeed loaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM