Matías
Matías

Reputation: 1

help with htaccess

I want to redirect this:

foo.com/xxx

... to this:

foo.com/somepage.php?id=xxx

This is how I do it:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/]+)$ http://foo.com/somepage.php?id=$1 [L]

the problem now, is that foo.com doesn't work any more. I can't see foo.com neither foo.com/index.php

help me! :)

Upvotes: 0

Views: 174

Answers (3)

grossvogel
grossvogel

Reputation: 6782

1) You don't need the RewriteCond line. It's intended to determine WHEN your rule applies, not WHICH PART of the request.

[EDIT] UNLESS, your RewriteCond is there to make this rule apply whenever the query string is empty. If that's it, then there's nothing wrong with it.

2) I think you need to include the first / in your rule, like this:

RewriteRule ^/([^/]+)$ /somepage.php?id=$1 [L]

[EDIT] Both your version and mine will match your index.php file, which might explain why your site is broken right now. If you don't want to match php files, you could add another condition like

RewriteCond ${REQUEST_URI} !^.*\.php$

3) For a rule like this, it might be helpful to add /? at the end (outside the parens, before the $), in case they look for foot.com/xxx/, which makes sense if you want it to look like a directory.

Upvotes: 1

Ben
Ben

Reputation: 16533

RewriteRule ^/([^/]+)$ /somepage.php?id=$1 [L]

Be careful tho, foo.com/1 is a BAD move on SEO.

Upvotes: 1

Josh
Josh

Reputation: 11070

Try:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(xxx=)$ /somepage.php?id=$1 [L]

Of course you didn't clearly specify what xxx= is...

Upvotes: 0

Related Questions