Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create optional RewriteCond in Apache

i have touble for my .htaccess config., this is part of config:

RewriteCond %{QUERY_STRING} ^token=(.*)
RewriteRule ^aplikasi/(.*).asp aplikasi.php?halaman=$1&token=%1

and result that config is:

http://{domain}/aplikasi/{$1}.asp?token={%1}

if i using this link:

http://{domain}/aplikasi/{$1}.asp

i have 404 error, i my question is : how to create like that with optional token prameter (i want to "?token={%1}" is optional)

like image 350
Abdul Aziz Al Basyir Avatar asked Sep 06 '17 07:09

Abdul Aziz Al Basyir


1 Answers

You have two possibilities.

If you want to allow either an empty query string or only token

RewriteCond %{QUERY_STRING} ^$ [OR]
RewriteCond %{QUERY_STRING} ^token=([^&\s]+)$ [NC]
RewriteRule ^aplikasi/(.+)\.asp$ /aplikasi.php?halaman=$1&token=%1 [L]

If you want to allow any query string

RewriteRule ^aplikasi/(.+)\.asp$ /aplikasi.php?halaman=$1 [L,QSA]
like image 74
Justin Iurman Avatar answered Dec 08 '22 10:12

Justin Iurman