htaccess的URL重写,忽略文件 [英] htaccess url rewriting, ignoring files
问题描述
我想拿出一个重写规则,但我有问题。
I am trying to come up with a rewrite rule, but I am having problems.
我需要的 - 那开头的网址 /服务/ XXX
被重定向到 /services/api.php?service=XXX
What I need - any url that starts with /services/XXX
to be redirected to /services/api.php?service=XXX
我也想忽略也可能匹配任何文件或文件夹。
I also want to ignore any files or folders that might also match.
我到目前为止有:
重写规则^服务/([A-Z] +)$ /services/api.php?service=$1 [NC,L]
但是,这并不在所有的工作,它显示了一个404页说,当我测试的文件丢失。
任何帮助深表AP preciated。
But this does not work at all, it shows a 404 page saying that file is missing when I test it. Any help is much appreciated.
推荐答案
要忽略存在只是忽略的RewriteCondS的文件。
To ignore the files that exists just ignore the "RewriteCond"s.
只是重写进入服务的一切/到api.php?服务...
Just rewrite everything that comes into services/ to api.php?service ...
将这个变成你的服务文件夹中。
Put this into your services folder.
小心你的编码,将文件保存为的.htaccess与EN code,你的服务器读取。
Be careful with your encoding, save the file as .htaccess with a encode that your server reads.
# .htaccess mod_rewrite
RewriteEngine On
RewriteRule ^(.*)$ api.php?service=$1 [QSA,L]
如果您不需要以避免文件,那么只要到:
If you don't need to avoid Files, then just go to:
# .htaccess mod_rewrite
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ api.php?service=$1 [QSA,L]
这篇关于htaccess的URL重写,忽略文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!