2

I have wampserver 2.4 and I can not seem to get Mod_Rewrite to work on it. I have enabled it in the Apache services and uncommented the mod_rewrite.so in the httpd.conf and restarted the server. I also checked my phpinfo() and it listed mod_rewrite under services.

The site I am testing it on is behind the address localhost/eb/index.php I was trying to test it on the event.php page in which the url looks like localhost/eb/event.php?id=1

This is what my .htaccess file looks like in the root of localhost/eb where my index.php file is located.

<IfModule mod_rewrite.so>
RewriteEngine on
RewriteBase /eb/
RewriteRule ^event/([0-9]+)/?$event.php?id=$1
</IfModule>

Even after this it still displays the url localhost/eb/event.php?id=1

Conner Burnett
  • 502
  • 1
  • 11
  • 24

2 Answers2

2

add the RewriteBase /eb/ on document root instead of /eb/ directory and add your all your rewrites on /eb/ directory.

update

On your http.conf

<Directory *>            
   # changed from None to FileInfo
   AllowOverride FileInfo          
</Directory>
hodl
  • 1,420
  • 12
  • 21
  • so under my www root folder I added an .htaccess file with RewriteEngine On RewriteBase /eb/ and then under the eb folder my .htaccess file has everything in it as the OP, but doesn't include the RewriteBase. After these changes the mod_rewrite still isn't working :-/ – Conner Burnett Jan 16 '14 at 02:06
  • @ConnerBurnett please check mod_rewrite using the following solution :http://stackoverflow.com/questions/9021425/how-to-check-if-mod-rewrite-is-enabled-in-php – hodl Jan 16 '14 at 02:09
  • after running the echo in_array('mod_rewrite', apache_get_modules()) from the link you gave me the result came back as 1. – Conner Burnett Jan 16 '14 at 02:24
  • I have a feeling it could be something with Wamp. I applied those changes and still no results. – Conner Burnett Jan 16 '14 at 04:30
  • Thanks, this pointed me in the right direction. I had to use `AllowOverride All` to get it working. – Gavin Aug 24 '14 at 14:55
2

You need an additional for external redirect also. Keep your .htaccess like this:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /eb/

RewriteCond %{THE_REQUEST} /event\.php\?id=([^\s&]+) [NC]
RewriteRule ^ event/%1? [R=301,L]

RewriteRule ^event/([0-9]+)/?$ event.php?id=$1 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • It worked! Would you be kindly enough to please explain why so many rules? All tutorials I have read have only shown to use the rewrite rules in the OP. Also, what do I need to do now so that my CSS scripts work on the pages that have been rewritten? It is a dynamic page so the css call is in header.php and that file is included in the other page files – Conner Burnett Jan 16 '14 at 14:10
  • For css/js issue use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with `http://` or a slash `/`. OR You can try adding this in your page's header: `` – anubhava Jan 16 '14 at 14:35
  • 2 rules are needed here. Rule 1: To redirect actual `/eb/event.php?id=123` to `/eb/event/123` and 2nd rule to internally rewrite `/eb/event/123` URI to the actual one `/eb/event.php?id=123`. – anubhava Jan 16 '14 at 14:36