0

Pretty much all the methods I found on the internet for this:

www.website.com/page?id=43432

to be like this

www.website.com/page/43432

are using htaccess, what I'm asking is, whether there is any other way to achieve this?

Havelock
  • 6,913
  • 4
  • 34
  • 42
Bob
  • 411
  • 1
  • 6
  • 12
  • Are you making php page from scratch? – Eddie Apr 01 '14 at 06:08
  • Yes I am. A little blogging system. The whole idea is for it to be from scratch. – Bob Apr 01 '14 at 06:09
  • You can put path names after your php script url without the query string and your script can parse that. like: `www.website.com/page.php/43432` the result will be that `$_SERVER['PATH_INFO']` will contain `"/43432"` – Tim Seguine Apr 01 '14 at 06:10
  • The thing is: Do you know why all the people use htaccess? Do you know the drawbacks of not using it? – Federico J. Apr 01 '14 at 06:11
  • Is there a particular reason against using htaccess? If so, you should expand on those limitations. Seems relevant to the question. – deceze Apr 01 '14 at 06:13
  • I think you still need to use htaccess. If you access www.website.com/page/43432 then it will look for page/43432 directory, so you need to redirect it using htaccess – Eddie Apr 01 '14 at 06:13
  • 1
    @Chococroc like you see in Tim Seguines example, without .htaccess and with apache, you will always have things like "page.php" in your url. That doesn't look as clean, so people prefer htaccess when dealing with apache + php. – eis Apr 01 '14 at 06:13
  • I believe I can't because the apache server does not allow me to. Something to do with an AllowOverride configuration or a lack of vps something, and there's no wiggle space on that one. – Bob Apr 01 '14 at 06:14
  • @eis exactly right. I just mentioned it because it is the only way as far as I know. There is no good reason as far as I can see not to use htaccess – Tim Seguine Apr 01 '14 at 06:15
  • @Kebab pretty much any shared host will allow htaccess usage. Talk to your system administrator. – Tim Seguine Apr 01 '14 at 06:17
  • 1
    Did and like I said there's no wiggle room on it. Also as a programmer I really want to know if there's any other way other than htaccess. – Bob Apr 01 '14 at 06:18
  • @Kebab the only way, I am pretty sure, is the one I mentioned in my comment. There is a hack that has significant drawbacks and might require htaccess usage: If you can set up a custom error page, you can use it to capture and process the original url, BUT you will never be able to see the GET or POST variables through it. But it does allow you to have urls that look however you want for anything that doesn't require GET or POST data. – Tim Seguine Apr 01 '14 at 06:20
  • @Kebab is this company internal or something? Seriously, even most cheapo web hosting plans allow it. – Tim Seguine Apr 01 '14 at 06:30
  • @TimSeguine Pretty much. Also for what I'm doing I need GET/POST 100% – Bob Apr 01 '14 at 06:36
  • 2
    Best solution? change hosting provider. – STT LCU Apr 01 '14 at 06:48
  • This question appears to be off-topic because it is about SEO and URLs. – Jukka K. Korpela Apr 01 '14 at 07:19
  • check this link http://stackoverflow.com/questions/16388959/url-rewriting-with-php – user986959 Apr 01 '14 at 07:21

1 Answers1

1

With Apache and PHP, as far as I know, there isn't.

Without .htaccess the best you can do is to have page like "page.php" which you will use to form all urls, like www.website.com/page.php/43432. That will add the .php to all your urls.

eis
  • 51,991
  • 13
  • 150
  • 199
  • Do you know of any example of such a page where I could check this out to see how it's done? – Bob Apr 01 '14 at 06:35
  • @Kebab if you open the url as in the answer, then you can access the superglobal variable `$_SERVER["PATH_INFO"]`, it will contain the string "/43432". Parse it and process it however you want. – Tim Seguine Apr 01 '14 at 11:27
  • @Kebab if you want a live example, see for example [poets.org](https://www.poets.org/page.php/prmID/58), their navigation links do this. – eis Apr 01 '14 at 11:31