.htaccess multiple parameters is not working - apache

I have a problem with htaccess rule because is not working. I already try to find any solution on google but still have not found yet.
The code is:
RewriteEngine ON
RewriteBase /deshop/
RewriteCond %{REQUEST_URI} ^/deshop/admin(.+)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ admin/index.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ index.php?p=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^\s]+)$ index.php?p=$1&b=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([0-9]+)$ index.php?p=$1&id=$2 [L]
The urls are working normally:
http://localhost/deshop/index.php to http://localhost/deshop/ -> home page from folder
http://localhost/deshop/admin/index.php to http://localhost/deshop/admin/ -> admin page from subfolder
http://localhost/deshop/index.php?p=tshirts to http://localhost/deshop/tshirts/
http://localhost/deshop/index.php?p=brand&b=John%20Player to http://localhost/deshop/brand/John-Player/
So that happen, last rule does not work.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([0-9]+)$ index.php?p=$1&id=$2 [L]
But last rule has worked yet. I really difficult. I want get url with parameters so look work :
http://localhost/deshop/index.php?p=single&id=0005 to http://localhost/deshop/single/0005
Or, what am I wrong? Any solution? Can you help me? Thanks a lot. By the way, my english is not good. I'm sorry!

Finally I have solved it.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/miistore/miiadmin$
RewriteRule ^(.+)$ miiadmin/index.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]
RewriteRule ^/?single/([^/d]+)/?$ index.php?p=single&id=$1 [L,QSA]
RewriteRule ^/?brand/([^\s]+)/?$ index.php?p=brand&b=$1 [L,QSA]

Related

Why does page not load without file extension

I have a page url /clubs/england/arsenal/ but it wont load, I unless it is shown as /clubs/england/arsenal.php.
I have already added the following to the .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
With your shown samples, could you please try following.
Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^(clubs/england)/(.*)/?$ $1/$2.php [NC,L]

RewriteRule to redirect whole domain to get parameter

I want to redirect a whole url to a query parameter with a RewriteRule in .htaccess
for example: http://server.com/http://google.com should be redirected to
http://server.com/index.php?url=http://google.com
so far i'm just able to make this work: http://server.com/google.com but when a : or / is contained, it doesn't work..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-z0-9_.-]+)$ index.php?url=$1 [L,NC,QSA]
thanks for help!
RewriteRule patter strips multiple / into one, better use RewriteCond here:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(.+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . index.php?url=%1 [L,NC,QSA]
Why not just do the TLD and then add the http:// in the rule. This is how I would do it.
This is the way I would use it so it doesn't "look" invalid. http://server.com/google.com
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-z0-9_.-]+)$ index.php?url=http://$1 [L,NC,QSA]

Apache Htaccess forwarding sub folders

I want to create a custom rule for htaccess so that all the URL's requested in the home folder such as localhost/asfsd will redirect to localhost/index.php?url=asfsd but if the user enters the following url localhost/asfsd- he must then be forwarded to localhost/info.php?url=asfsd . Here is my current .htaccess configuration :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?url=$1 [L,QSA]
You can try these 2 rules:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)-$ /info.php?url=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?url=$1 [L,QSA]
Try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\-$ info.php?url=$1 [L,QSA]
RewriteRule ^(.*) index.php?url=$1 [L,QSA]

Multiple .htaccess rules?

I'm getting the grip of .htaccess, but now i'm stuck in a situation where there's multiple redirects needed.
website/werknemers/5
website/lijst/5
Those links should work, redirecting from
index.php?page=werknemers&klant=5
index.php?page=lijst&lijst=5
I'm using the following .htaccess, which is working! but only the one's i put at the top of the document
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ index.php?page=$1&klant=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ index.php?page=$1&lijst=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L]
Since your patterns are exactly the same, there is no difference between the first and second rules, so the first always matches and you will always get the klant query string no matter what. You can hardcode the page names if that's the only thing that's different:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^werknemers/(.*)$ index.php?page=werknemers&klant=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^lijst/(.*)$ index.php?page=lijst&lijst=$1 [L]

.htaccess RewriteRule country codes and urls

I am using the following .htaccess code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ca/(.+)$ /index.php?p=$1&c=ca [L,QSA]
RewriteRule ^fr/(.+)$ /index.php?p=$1&c=fr [L,QSA]
RewriteRule ^(.+)$ /index.php?p=$1 [L,QSA]
In order to achieve the following effect:
http://xyz.com/ca/test -> http://xyz.com/index.php?p=test&c=ca
http://xyz.com/fr/test -> http://xyz.com/index.php?p=test&c=fr
http://xyz.com/test -> http://xyz.com/index.php?p=test
But it is failing with a server error. Any ideas on how to fix it?
Thanks
RewriteCond conditions only apply to the RewriteRule that immediately follows the condition(s). Your last 2 rules don't have any conditions on them and the rules are looping. Just add the 2 conditions in front of the last 2 rules:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ca/(.+)$ /index.php?p=$1&c=ca [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^fr/(.+)$ /index.php?p=$1&c=fr [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?p=$1 [L,QSA]