I want to change my web url from www.site.com/maintenance.php?m=1 to a mime type url(as I was told) like www.site.com/maintenance/1. How do I do that on a apache localhost server?
I heard you must do something with htaccess so I want to say 2 thing about my htaccess
My htaccess in located in htdocs/folder/ .htaccess because I have multiple sites in my htdocs so I out every site files in a folder
I already have this code in my htaccess. If you're going to ask whether it's working , yes it's working I stole it from some cpanel hosting for my custom 404 error page
http://i.stack.imgur.com/TpeZC.jpg
And also, how do I get the value of /1 after the /maintenance/?
Thank you in advance
Use this in your .htaccess
file
RewriteEngine On
RewriteRule ^maintenance/(.*)$ maintenance.php?m=$1 [QSA,L]
You get the value of m
as you normally get. $m = $_GET['m'];
What you are trying to accomplish is called mod_rewrite , not changing mime type .
In your case, you can try this inside your .htaccess
file:
RewriteRule ^maintenance/([0-9]+)$ maintenance.php?m=$1 [QSA,L]
Basically what the above means is that for every numerical values that follow "maintenance/" in your typed URL, take the number and pass it as the m
value for "maintenance.php" script. So, in your "maintenance.php" file, you can access the value with $_GET['m']
.
Note that if your m
can accept anything other than numbers, or if your other files under "maintenance" folder can contain numbers only, thing gets a bit more complicated. You will then need additional rules to filter out the files you don't want to be converted to $_GET['m']
value.
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.