nitiphone2021 Posted February 10, 2021 Share Posted February 10, 2021 (edited) RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z_]+)$ function.php?func=$1 [L,QSA] RewriteRule ^([a-z_]+)/$ function.php?func=$1 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/?$ function.php?lang=$1&func=$2 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/([a-z_]+)/?$ function.php?lang=$1&func=$2&sub=$3 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/([a-z_]+)/([0-9]+)/?$ function.php?lang=$1&func=$2&sub=$3&my_id=$4 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/([a-z_]+)/([0-9]+)/([0-9]+)/?$ function.php?lang=$1&func=$2&sub=$3&parent_id=$4&my_id=$5 [L,QSA] I think .htaccess will be the first file when user request to and I try to send paramter to file function.php to show the request URL of user. but when I tried it. brownser open index.html file. question: 1. why not open function.php? 2. function.php can get parameter by $_POST or $_GET? http://localhost/testsmarty/ Edited February 10, 2021 by nitiphone2021 Quote Link to comment https://forums.phpfreaks.com/topic/312118-htaccess-first-time/ Share on other sites More sharing options...
nitiphone2021 Posted February 10, 2021 Author Share Posted February 10, 2021 1 hour ago, nitiphone2021 said: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z_]+)$ function.php?func=$1 [L,QSA] RewriteRule ^([a-z_]+)/$ function.php?func=$1 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/?$ function.php?lang=$1&func=$2 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/([a-z_]+)/?$ function.php?lang=$1&func=$2&sub=$3 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/([a-z_]+)/([0-9]+)/?$ function.php?lang=$1&func=$2&sub=$3&my_id=$4 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/([a-z_]+)/([0-9]+)/([0-9]+)/?$ function.php?lang=$1&func=$2&sub=$3&parent_id=$4&my_id=$5 [L,QSA] I think .htaccess will be the first file when user request to and I try to send paramter to file function.php to show the request URL of user. but when I tried it. brownser open index.html file. question: 1. why not open function.php? 2. function.php can get parameter by $_POST or $_GET? http://localhost/testsmarty/ I changed htaccess to .htaccess but the result still the same Quote Link to comment https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584342 Share on other sites More sharing options...
requinix Posted February 10, 2021 Share Posted February 10, 2021 1 hour ago, nitiphone2021 said: 1. why not open function.php? Because none of your URL rewriting rules apply to / Quote 2. function.php can get parameter by $_POST or $_GET? $_POST will work as long as you do not use the [R] flag or cause a redirect by some other means. $_GET will work as long as you do use the [QSA] flag. Quote Link to comment https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584343 Share on other sites More sharing options...
nitiphone2021 Posted February 10, 2021 Author Share Posted February 10, 2021 1 . RewriteRule ^([a-z_]+)$ function.php?func=$1 [L,QSA] 2 . RewriteRule ^([a-z_]+)/$ function.php?func=$1 [L,QSA] 1. It's correct that we use both command line? or we just use only one line? 2. below command it's mean (if user request a existing file, then process next command?) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d Quote Link to comment https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584349 Share on other sites More sharing options...
requinix Posted February 10, 2021 Share Posted February 10, 2021 8 hours ago, nitiphone2021 said: 1 . RewriteRule ^([a-z_]+)$ function.php?func=$1 [L,QSA] 2 . RewriteRule ^([a-z_]+)/$ function.php?func=$1 [L,QSA] 1. It's correct that we use both command line? or we just use only one line? If you want to allow trailing slashes in your URLs then keep one and make the slash optional. But that still doesn't cover the root / URL. Also I missed that your first Rule only applies when the path does not exist as a file or directory. And index.html exists. Because: 8 hours ago, nitiphone2021 said: 2. below command it's mean (if user request a existing file, then process next command?) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond only applies to the single next RewriteRule. Rather than repeat those every single time, most applications do it a smarter way: route all requests through your PHP script and have it look at the URL and decide what to do. Quote Link to comment https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584355 Share on other sites More sharing options...
nitiphone2021 Posted February 11, 2021 Author Share Posted February 11, 2021 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z_]+)$ function.php?func=$1 [L,QSA] RewriteRule ^([a-z_]+)/$ function.php?func=$1 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/?$ function.php?lang=$1&func=$2 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/([a-z_]+)/?$ function.php?lang=$1&func=$2&sub=$3 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/([a-z_]+)/([0-9]+)/?$ function.php?lang=$1&func=$2&sub=$3&my_id=$4 [L,QSA] RewriteRule ^([a-z]+)/([a-z_]+)/([a-z_]+)/([0-9]+)/([0-9]+)/?$ function.php?lang=$1&func=$2&sub=$3&parent_id=$4&my_id=$5 [L,QSA] as my purpose code,I want to send parameter of url to my function.php and make decide that the request can access the URL. but as my tried, If I go to put the URL on brownser as normally, it's work. ---- If I use ajax go to the URL, it's no need authentication of function.php make decide. Is it right ? Quote Link to comment https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584365 Share on other sites More sharing options...
requinix Posted February 11, 2021 Share Posted February 11, 2021 I'll repeat it: 1. Those two RewriteConds are only applying to the first RewriteRule. 2. Better than repeating those two RewriteConds six times, you should have all !-f !-d URLs go through function.php. Then it looks at the URL and determines which func/lang+func/lang+func+sub/whatever to use, like how the .htaccess is trying to do now. 3. You do not have any RewriteRules that will apply to /. That means Apache will use your index.html. AJAX is not authentication, you need all of this stuff for everything. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584367 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.