0

I have a url similar to:

http://.../user.php?do=login

and with PHP I'd like to make it look like:

http://.../user/login/

How would I go about this? Most places seem to be talking about .htaccess, of which I don't have access to.

Thanks.

  • 1
    If you cannot modify server settings, not even using htaccess then it will be a tough endeavor. PHP itself doesn't rewrite urls, its the web server that does – Hanky Panky Apr 28 '14 at 08:51
  • this will help http://stackoverflow.com/questions/2126762/url-rewriting-in-php-without-htaccess ,but you will not get beautiful url which is possible through mod_rewrite, can you provide more details about why you do't have access to .htaccess file, if you are on shared hosting you can create one in your webroot folder – Manish Apr 28 '14 at 08:52
  • May be this gonna help [URL rewriting in PHP without htaccess][1] [1]: http://stackoverflow.com/questions/2126762/url-rewriting-in-php-without-htaccess?lq=1 – Bijay Rai Apr 28 '14 at 09:05

2 Answers2

0

htaccess rewrite for query string

create a .htaccess file and write

RewriteRule ^(.*)$ user.php?url=$1 [L,QSA]
Community
  • 1
  • 1
Rotari Radu
  • 645
  • 6
  • 13
  • 1
    *"Most places seem to be talking about .htaccess, of which I don't have access to."* – Daniel W. Apr 28 '14 at 08:52
  • if you have ftp or ssh access then .htaccess file can be placed in document root directory where is your index.php(or any other directory in your project), if it is not there you can simply create it, be aware that .htaccess is invisile so additional setting for your file management program might be required. if you really have no ftp access then you should rename your files like this: for url http://.../user/login there wil be directory /user/login/index.php – Rotari Radu Apr 28 '14 at 11:19
  • `.htaccess` MUST BE ENABLED in the config. Simply creating the file well maybe you are lucky but OP doesn't seem to be. (See `AllowOverride`) – Daniel W. Apr 28 '14 at 11:23
0

As other people said, just use links like /index.php/nice/looking/url. The "index.php" in the middle of the URL might look a little strange, but I don't think it's possible to have it look better without .htaccess

Else, you could ask your hoster to redirect any URL to /index.php so that you can handle URL rewriting without having /index.php in your URL.

Then you can just use a regex match to detect what file to include. preg_match('@[/]{1}([a-zA-Z0-9]+)@', $_SERVER["PATH_INFO"], $matches) ($matches will contain all "parts" of the url in an array)

Be careful with including the files, use a whitelist so you're sure nobody would be able to load internal files.

source URL rewriting in PHP without htaccess

Community
  • 1
  • 1
Bijay Rai
  • 961
  • 1
  • 12
  • 32