Andrew Appleby
Andrew Appleby

Reputation: 183

Using .htaccess to use subdirectory as a parameter

I've had a real tough time trying to search for the exact htaccess code that will allow me to do the following:

Visiting: http://www.domain.com/wildcard

Should show: http://www.domain.com/

But the URL should still read: http://www.domain.com/wildcard

So basically a transparent redirection... seems fairly straight-forward, but surprisingly hard to search for. The PHP in index.php is already set up to parse the subdirectory and read it as a parameter, but unfortunately my client never supplied me with the .htaccess file. #developerproblems

Thanks!

Upvotes: 1

Views: 871

Answers (2)

SaidbakR
SaidbakR

Reputation: 13544

We will suppose that you have to receive a url parameter called param so your rewrite rule should be:

RewriteEngine On
RewriteRule ^([^/]*)$ /?param=$1 [L]

By this way any http://www.domain.com/AnythingHere will render the contents of http://www.domain.com/?param=AnythingHere so the home page is rendered.

However, such solutions, they are not change the contents, they may leads to SEO problems for repeated contents, So the solution of anubhava is better for SEO according to your usage.

Upvotes: 0

anubhava
anubhava

Reputation: 785156

You just need this ErrorDocument 404 line at top of your .htaccess:

ErrorDocument 404 /

This will show home page for any request that is not a file or directory and results in a 404.

Upvotes: 4

Related Questions