recoup8063
recoup8063

Reputation: 4280

Mod Rewrite ignore url

I am creating a site where instead of using GET variables I will just be looking at the url. How would you create a mod_rewrite rule that no matter what directs the user to index.php(Or some page)?

EX:
User enters: www.example.com/blog/programming/postName
User still sees www.example.com/blog/programming/postName in the adress bar but www.example.com/index.php is shown

I have tried:

RewriteRule    ^([a-z]+.)?$    /index.php    [NC,L]  

But that only changes the page for one directory(only worked for www.example.com/worksNow/

RewriteRule    ^(.*)    /Blog3/index.php    [NC,L]

But It got a server error

Upvotes: 0

Views: 156

Answers (2)

covener
covener

Reputation: 17872

This behavior/recipe doesn't require mod_rewrite, see FallBackResource.

http://httpd.apache.org/docs/2.2/mod/mod_dir.html#fallbackresource

Upvotes: 1

anubhava
anubhava

Reputation: 785146

You can use this rule:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L]

This means if any request that is not for a file or directory then internally rewrite that to /index.php

Reference: Apache mod_rewrite Introduction

Upvotes: 1

Related Questions