Reputation: 1059
I'm new on .htaccess
and rewrite rules
.
So if my question is not relevant, please forgive me.
I have below htaccess code.
RewriteRule ^([^/]+)/([^/]+)/?$ article-list.php?link=$1&page=$2 [L,QSA]
If i visit url like www.example.com/category/0
it works.
But if i strip page url and last slash www.exapmle.com/category
i see an ugly 404 page.
What is wrong with my htaccess directive?
Thanks in advance.
EDIT: Compeletely .htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^haber/([^/]+)-([^/]+)/?$ article.php?link=$1&i=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ article-list.php?link=$1&page=$2 [L,QSA]
Upvotes: 1
Views: 116
Reputation: 19026
This is a correct behaviour.
Actually, in a regular expression, a +
means at least one
.
When you use ([^/]+)
it means at least one character which is not a slash
.
Your rule ^([^/]+)/([^/]+)/?$
means at least one character which is not a slash
/ at least one character which is not a slash
optional slash.
That's why it does not work with only the first part url.
If you also want to handle example.com/category
you'll need another rule:
RewriteRule ^([^/]+)/?$ article-list.php?link=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ article-list.php?link=$1&page=$2 [L]
Upvotes: 1