I have a file http://sub.domain.com/apush/noteGetter.php
that handles dates in the format d-m-y
through noteGetter.php?date=d-m-y
. For example, I'll use January 13th, 2017. I want the url to be http://sub.domain.com/apush/notes/2017/01/13
. I know this can be accomplished using mod_rewrite through htaccess, but I have little experience with regular expressions and even less with htaccess. What rules and conditions would I need to add to get this URL rewritten?
我有一个文件http://sub.domain.com/apush/noteGetter.php,它通过noteGetter.php?date=d-m-y格式处理日期。例如,我将使用2017年1月13日。我希望url是http://sub.domain.com/apush/notes/2017/01/13。我知道这可以通过mod_rewrite through htaccess实现,但是我对正则表达式没什么经验,使用htaccess就更少了。我需要添加哪些规则和条件来重写这个URL ?
Update
更新
Current 'apush' directory .htaccess
当前“apush”目录. htaccess
RewriteEngine on
RewriteRule ^notes/(\d{4})/(\d{2})/(\d{2})$ "noteGetter.php?date=$3-$2-$1"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [L]
DirectoryIndex home.php
ErrorDocument 404 'https://www.domain.com/404'
Current 'root' directory .htaccess
当前的根目录. htaccess
AuthType Basic
AuthUserFile /home/tsenter/sub.domain.com/.htpasswd
AuthName "Members Area"
require valid-user
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^notes/(\d{4})/(\d{2})/(\d{2})$ "noteGetter.php?date=$3-$2-$1"
RewriteRule ^([^\.]+)$ $1.php [NC,L]
DirectoryIndex home.php
ErrorDocument 404 'https://www.domain.com/404'
Update 2
更新2
New 'apush' directory .htaccess
新的“apush”目录. htaccess
RewriteEngine on
RewriteRule ^notes/(\d{4})/(\d{2})/(\d{2})$ "noteGetter.php?date=$3-$2-$1"
New 'root' directory .htaccess
新的根目录. htaccess
AuthType Basic
AuthUserFile /home/tsenter/sub.domain.com/.htpasswd
AuthName "Members Area"
require valid-user
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
DirectoryIndex home.php
ErrorDocument 404 'https://www.domain.com/404'
1 个解决方案
#1
2
I understand from discussion you are looking to place the rules in a .htaccess
file in your apush
directory. You would need this in your apush
.htaccess
file:
我从讨论中了解到,您希望将规则放在apush目录中的.htaccess文件中。你需要在你的apush .htaccess文件:
RewriteEngine on
RewriteRule ^notes/(\d{4})/(\d{2})/(\d{2})$ "noteGetter.php?date=$3-$2-$1"
This is a simple matching of any four numbers for year, any two numbers for month, any two numbers for day. Simplest to do the verification in your script and have a simple regex here.
这是一个简单的匹配任何四个数字为一年,任何两个数字为一个月,任何两个数字为一天。在脚本中进行验证最简单,这里有一个简单的regex。
#1
2
I understand from discussion you are looking to place the rules in a .htaccess
file in your apush
directory. You would need this in your apush
.htaccess
file:
我从讨论中了解到,您希望将规则放在apush目录中的.htaccess文件中。你需要在你的apush .htaccess文件:
RewriteEngine on
RewriteRule ^notes/(\d{4})/(\d{2})/(\d{2})$ "noteGetter.php?date=$3-$2-$1"
This is a simple matching of any four numbers for year, any two numbers for month, any two numbers for day. Simplest to do the verification in your script and have a simple regex here.
这是一个简单的匹配任何四个数字为一年,任何两个数字为一个月,任何两个数字为一天。在脚本中进行验证最简单,这里有一个简单的regex。