2

I've been trying out a few permutations and still can't figure this out. I have 3 requirements:

  • forward everything from xxx.php to just xxx
  • mydomain/sentence actually loads mydomain/page?q=sentence
  • exclude a folder e.g. mydomain/logs

So I managed to get the first two to work using:

Options +FollowSymLinks
RewriteEngine On
#RewriteCond %{REQUEST_URI}!^/panel/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ page.php?q=$1 [NC,L]
# RewriteRule ^([^\.]+)$ $1.php [NC,L]

If I uncomment the third line everything breaks. Any help is appreciated! Also please point out any errors I might have. Thanks in advance! I apologize for the bad formatting. The editor kept giving errors no matter how I typed.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
phantomhive
  • 145
  • 1
  • 1
  • 11
  • https://stackoverflow.com/questions/1848500/htaccess-mod-rewrite-how-to-exclude-directory-from-rewrite-rule – Giacomo M Dec 03 '20 at 12:19

1 Answers1

2

You can try the following rule to only redirect to PHP files that actually exist. I also believe that this rule has to come before the other rewrite rule because the condition of the other rule would also match.

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

#RewriteCond %{REQUEST_URI}!^/panel/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ page.php?q=$1 [NC,L]
Thakkie
  • 604
  • 4
  • 17
  • oh god this works! Thank you so much! It looks so similar yet it's different. I have so many questions - can I ask you more, or you have a link that might point me to more enlightenment about this? Thank you so much again! – phantomhive Dec 03 '20 at 12:47
  • There is a lot of information about mod_rewrite on the net, but I am not aware of any good sources or tutorials. I do remember having a lot of difficulties when I started using it. I'm always open for questions, but SO does not offer any way to communicate outside of the regular question/answer/comment flow – Thakkie Dec 03 '20 at 13:00
  • you are right, I didn't even notice the lack of a dm function here. hmm. I will check out your profile and hope I don't look like a stalker. – phantomhive Dec 03 '20 at 14:40