Jump to content

Recommended Posts

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/

directory.png

Edited by nitiphone2021
Link to comment
https://forums.phpfreaks.com/topic/312118-htaccess-first-time/
Share on other sites

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/

directory.png

I changed htaccess to .htaccess but the result still the same

directory.png

Link to comment
https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584342
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584343
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584349
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584355
Share on other sites

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 ?

Link to comment
https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584365
Share on other sites

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.

  • Great Answer 1
Link to comment
https://forums.phpfreaks.com/topic/312118-htaccess-first-time/#findComment-1584367
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.