views:

240

answers:

4
From : www.example.com/cut/456
To : www.example.com/cut/index.php?tag=456

I try this and it doesn't work

RewriteEngine On
RewriteRule ^([^/]*)$ /cut/index.php?tag=$1 [L]
+1  A: 

unless your .htaccess located in cut directory, it should be better to use:

RewriteRule ^cut/(.+)/?$ /cut/index.php?tag=$1 [L]

otherwise

RewriteRule ^(.+)/?$ index.php?tag=$1 [L]

should do. It seems to be the issue with your substitution string, it's hard to say what exactly is the cause since doesn't work is not a sufficient description of a problem.

SilentGhost
The requested URL /cut/15 was not found on this server.
Waseem
if it's in a folder shouldn't it be:RewriteRule ^(.+)/?$ ../index.php?tag=$1 [L]not tested...
Michal M
no .
SilentGhost
A: 

If you just expect integer values, you should restrict your pattern to such values:

RewriteRule ^([1-9][0-9]*)$ index.php?tag=$1 [L]

The problem with your current pattern is that ^([^/]*)$ does also match index.php (/cut/index.php without the per-directory path prefix) and thus may cause an infinite loop.

Gumbo
A: 

Is the server actually loading .htaccess? You can check this by chucking garbage at the end of the file and seeing if you get an error for it.

If it's not, AllowOverride is probably set to None somewhere higher in the directory tree. Try declaring a <Directory /path/to/cut> somewhere in your Apache's main configuration file and putting AllowOverride All in it.

Jason Musgrove
+1  A: 
RewriteEngine On
RewriteBase /cut/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /index.php?tag=$1 [L]

It's work with this

Waseem