我真的很難與正則表達式和mod_rewrite,並試圖更好地理解。我有一些重寫腳本以及我認爲正在發表的評論。請讓我知道我是否準確地描述了正在發生的事情。謝謝瞭解mod_rewrite和正則表達式
# don't do the following if Apache isn't configured with mod_rewrite
<IfModule mod_rewrite.c>
# self explanatory
RewriteEngine on
# Reference everything from Apache root (i.e. /var/www/html)
RewriteBase/
# Create a condition if statement and execute the following rules until the next condition is reached.
# This one checks if the request is a valid directory, a valid file, or a valid symbolic link
# The % symbol has something to do with backreference of the matched string in the condition.
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
# Don't do anything (how?), and the [L] means to not match this condition anymore
RewriteRule^- [L]
#^and $ are the start and end of the patern.
# ([^/]+) takes all characters up to the first /,
# and then adds one more character because the + which is the /,
# and stores it as $1.
# It will only be matched, however, if a/follows plus 0 or 1 character due to the ?.
# Then redirect by adding ?p=$1 where $1 is the stored variable described above.
# The L flag means don't try to do it again, and QSA somehow adds the previous URL to it.
RewriteRule ^([^/]+)/?$ ?p=$1 [L,QSA]
# close if statement
</IfModule>
你的問題是什麼? –
@RahilWazir他沒有問題。閱讀文件中的評論,他想知道他對規則的解釋以及他們的工作方式是否正確。 –
瞭解正在發生的事情!這就像黑魔法,幾乎不可能排除故障。 – user1032531