不使用.htaccess简化URL

How to modify URL such www.mysite.com/dir.php?ID=123

to www.mysite.com/dir/123 without using or involving .htaccess

cause I can't access .htaccess on our server.

If this is your own application and not the standard framework/CMS then you can implement your own rewrite engine in PHP so the URLs would look like www.mysite.com/index.php/dir/123. That's slightly worse than the clean URLs but that's the best you can achieve.

When you run the url like that the $_SERVER['PATH_INFO'] PHP variable would store "/dir/123" which is then your job to parse and transform to the params you need and then invoke or include the right script.

IIRC Kohana is built like that. So you can look their code for an inspiration.

The only other option is using a rewrite engine on the web server software, e. g. mod_rewrite for Apache.

But as long as you don't even control files on your server, you probably don't have access to Apache configuration.

Your web app/CMS should have support for nice URLs too.

Short story is:

You can't

At least you should be able to use .htaccess to normally do this. If you can't even use that, other options will most probably also be limited out for you.

But there is one work-around that you MAYBE (I'm absolutely not sure) can use...

Are you allowed to set your own 404 error pages?

If so, try setting a 404page.php that acts as your entry point, sends out a http_response_code(200); and does what it further should do.

Off course you should remove any index.php from your public_html and not use any of the URLS that should be handled by the handler, so they will lead you to the 404page.php.

(Let me know if this worked :). )