0

So far, I have made my .htaccess to let me remove the ".php" extension, but that isn't enough for me. I want to be so that example.com/test?id=asdfjK could be able to be accessed as example.com/asdfjK. So that it accepts only the main php get argument in the URL (I don't know what to call them.

Here is my .htaccess file so far:

RewriteEngine On RewriteRule ^([a-zA-Z0-9_]+)$ index.php?page=$1 RewriteRule ^([a-zA-Z0-9_]+)/$ index.php?page=$1 RewriteRule ^([a-zA-Z0-9_]+)$ /image.php?ID=$1 RewriteRule ^([a-zA-Z0-9_]+)/$ /image.php?ID=$1 
1
  • Does anyone that is on right now know about how to do this? I've read other questions, but the answers haven't helped me. Commented Jan 20, 2014 at 6:30

2 Answers 2

1

There's no way to differentiate between what gets sent to index.php and what gets sent to image.php. The patterns are identical, which means everything will match the first one and nothing will get routed to image.php. You've got to add something to the url so that you can match against it. Something like:

http://example.com/image/abcdefg123456 

And that means the htaccess file would look something like:

RewriteEngine On RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?page=$1 [L,QSA] RewriteRule ^image/([a-zA-Z0-9]+)/?$ image.php?page=$1 [L,QSA] 
Sign up to request clarification or add additional context in comments.

1 Comment

Now when I go to my domain and use /image/sadfklj9 (random code), Chrome loads for a second or two then tells me it runs a redirect loop.
0

The PHP arguments after the question mark are called the "query string".

Try something like this:

RewriteEngine On RewriteCond %{REQUEST_URI} !^/index\.php RewriteRule ^([a-zA-Z0-9]+)$ /index.php?page=$1 [L] 

This should redirect anything from:

http://example.com/abc123 

To:

http://example.com/index.php?page=abc123 

See also:

2 Comments

That didn't work :(. The examples just gives me the same error as in my previous comment on the answer above.
I think you can get around the infinite redirect by putting in a RewriteCond above your rule. Basically, I think because the rule matches the rewritten output, it will rewrite it again (and again, and so forth). A condition prevents that by only applying the rule if it hasn't already been rewritten. See the updated answer above.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.