I have a file http://sub.domain.com/apush/noteGetter.php
that handles dates in the format dmy
through noteGetter.php?date=dmy
. 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?
Update
Current 'apush' directory .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
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
New 'apush' directory .htaccess
RewriteEngine on
RewriteRule ^notes/(\d{4})/(\d{2})/(\d{2})$ "noteGetter.php?date=$3-$2-$1"
New 'root' directory .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'
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.