Reputation: 553
I have URLs like book.php?id=23
and using htaccess to make them book/id/title
I tried this
RewriteRule ^book/([0-9]+)/([^/]+)/?$ book.php?id=$1 [NC,L,QSA]
but it didn't work, it was forwarding to books.php
but no $_REQUEST
data
it turned out it was because the url reference was the same as the name as the php file I was calling with help from the community to work around this worked
RewriteRule ^books/([0-9]+)/([^/]+)/?$ book.php?id=$1 [NC,L,QSA]
this is my current working .htaccess:
RewriteEngine On
RewriteRule ^kitap/([0-9]+)/([^/]+)/?$ book.php?id=$1 [NC,L,QSA]
RewriteRule ^yyin/([0-9]+)/([^/]+)/?$ yayin.php?id=$1 [NC,L,QSA]
RewriteRule ^proje/([0-9]+)/([^/]+)/?$ project.php?id=$1 [NC,L,QSA]
every online tutorial I've ever seen uses examples like ^product and product.php, or ^category and category.php so I don't know why this should be. Maybe someone else can shed some light on this?
Upvotes: 1
Views: 172
Reputation: 784898
Most likely you have MultiViews
on which conflicts with rewrite rules.
Fulle .htaccess: (Goes in DOCUMENT_ROOT directory)
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^kitap/([0-9]+)/([^/]+)/?$ book.php?id=$1 [NC,L,QSA]
RewriteRule ^yyin/([0-9]+)/([^/]+)/?$ yayin.php?id=$1 [NC,L,QSA]
RewriteRule ^proje/([0-9]+)/([^/]+)/?$ project.php?id=$1 [NC,L,QSA]
RewriteRule ^books/([0-9]+)/([^/]+)/?$ book.php?id=$1 [NC,L,QSA]
Upvotes: 0
Reputation: 2475
I started messing with this after our small discussion on your original question and I'm starting to think it depends on the server configuration and whether or not it will run extensionless scripts.
My dev server, for example, will run extensionless scripts, i.e. typing /xyz will display xyz.php
A rewrite rule of
RewriteRule ^category/([0-9]+)/([^/]+)/?$ category.php?id=$1 [NC,L,QSA]
does not work, however
RewriteRule ^categories/([0-9]+)/([^/]+)/?$ category.php?id=$1 [NC,L,QSA]
does work.
On my hosting server, which does not support extentionless scripts, www.mydomain.com/xyz will give me a 404 error, but:
RewriteRule ^category/([0-9]+)/([^/]+)/?$ category.php?id=$1 [NC,L,QSA]
works as expected.
I can only assume that when the server supports extensionless scripts then the rewrite rule is ignored if the alias is identical to the script name.
Upvotes: 1