user1620152
user1620152

Reputation: 134

htaccess mod_rewrite giving me 404

SO I have this in my .htaccess file

RewriteEngine On
RewriteBase /core/
RewriteCond %{QUERY_STRING} ^page=([0-9]+)$
RewriteRule ^page page/%1/? [L]

my url is

http://localhost/core/page.php?page=8

with the rules applied I'm getting..

Not Found
The requested URL /core/page/8/ was not found on this server.

This is running on wampserver 2.2

the file structure looks like

c:/wamp/www/core

the .htaccess is inside the /core/ directory. What is it that I'm missing.. i've checked my apache.conf file and it looks fine.

Upvotes: 0

Views: 66

Answers (1)

kjetilh
kjetilh

Reputation: 4976

I think you got it the wrong way around. When logically thinking of rewriting you don't rewrite original URL to new URL (for example page.php?page=8 to page/8/) you actually rewrite page/8/ to page.php?page=8. You tell the server how it should interpret the unfamiliar URL.

So if I understood correctly what you want to achieve is:

  1. User visits localhost/core/page/8/
  2. User is served (under the hood) localhost/core/page.php?page=8

I believe the following RewriteRule will do the trick (The query string condition is not necessary):

RewriteRule ^page/(\d+)/$ page.php?page=$1 [L]

Upvotes: 2

Related Questions