Hello Community,
I was wondering if it is possible to use an ID ($_GET) after a file in the address bar so it would look like this
Instead of

I know there is a way of doing something like that but I'm only getting it to work on the index.php file using .htaccess
This is the .htaccess code I know works for the index.php file:

RewriteEngine on
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)$ index.php?id=$1

But I'm not sure if there is a way to change that so it works on another file, it is in the same directory as the index.php file.

I've tried change to "RewriteBase /" to "RewriteBase /product.php" but it won't work.

So is there anyway to get this working?

I think you could add

RewriteRule ^product.php/([a-zA-Z0-9]+)$ product.php?id=$1

to get that working. Or you could use this:

RewriteEngine on

Options -Indexes

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

to redirect everything to your index page, and then use $_SERVER['REQUEST_URI'] to parse the URI and load the appropriate files.

@minitauros I tried RewriteRule ^product.php/([a-zA-Z0-9]+)$ product.php?id=$1 and it didn't work and I'm not to fond of the second code. This is what I'm getting when I try it "No input file specified.".

@diafol I don't like the whole idea of every .html page being redirected to the id.

I've tried this and it has finally worked.

RewriteEngine On
RewriteRule ^product.php/([0-9]+)$ /littledevines/product.php?id=$1 [L]

So how do I get it so I don't have to have the .php extension? I've tried many way of doing this but they never seem to work.

I don't know if this will help but I'm hoasting with GoDaddy

Member Avatar


Look at my previous post - just leave off the .php in the first rewrite parameter.

It comes back saying the page cannot be found.

Member Avatar


Did you try the generator? I've never had any problems with it.

Ok after a bit of Googling and looking back on what yous have posted I've put together this.

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /littledevines/
RewriteRule ^product/([0-9]+)$ product.php?id=$1 [L]

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

And it is indeed doing what I wanted but no styling on the product page. So is there a way of moving around this with out direct linking the css and js files?

Member Avatar


You can make the css and js links absolute (with the http:// ...) or you can employ exceptions, e.g.

RewriteRule ^(js|css)($|/) - [L]

That's not working, what should it look like with the code I posted before?

Member Avatar


Dunno - I just took it out of an old project of mine -

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(js|css|pages|locale)($|/) - [L]
RewriteRule ^([^/]*)/([^/]*)/*$ /index.php?lang=$1&page=$2 [L]

How I'd shoehorn that to your needs I'm unsure. Anybody else?

I might just have to go with directly linking the files. I'll see how that goes.