How do I rewrite URLs in PHP without htaccess?

I have a question: how do I rewrite URLs in PHP without htaccess ?
can you explain .

You can’t. You could set up a router, but that would also require .htaccess tricks.

6 Likes

Can you know any htaccess tricks. Pleas tell me that I am complete my work.
Thanks

It depends on what you need to do, what are you trying to achieve?

6 Likes

I am not sure what you mean by “rewrite URLs in PHP”.

Do you mean redirect to another page? Like this…

<?php header("Location: http://www.redirecturl.com/"); ?>

You would use the module “Mod Rewrite” to change the appearance of URLs (it’s enabled by default). This function is handled by the web server (Apache) using the .htaccess file.

There is no equivalent to this behavior in PHP because PHP is not a web server.

It’s my comment. Doesn’t it?
It can be equivalent. Because they same - have run time on server.
even looks like apache is the first handler. php is independent module object i mean did you ever heard php run without apache. There many php server writer without apache who named it product as php server.

That is true. I think he is just talking about a PHP script though.

1 Like

I don’t quite know what you are talking about. Let’s try to keep this on-topic though please.

4 Likes

Yes, PHP has a built-in server for development, but we use Apache here.
And like I said earlier, you can’t rewrite URLs without some sort of .htaccess code.

5 Likes

Yes, and I could clarify a bit as to why.

Apache is a web server. It handles web requests. PHP, although used for websites, is a server-side language that allows you to execute processes when a page is accessed that has PHP code embedded in it. A server-side JavaScript, if you will.

PHP’s job is not to route traffic. Apache is the web server and so that is its job.

htaccess contains the code necessary for Apache to route traffic (to your wants, anyways), and that is why you will need it for rewriting URLs.

6 Likes

Even for some script, PHP has a look like javascript. It is not.
Php is same with compile programs. Its like windows itself. Can same with apache. With his beloved son .htaccess though.

PHP is not like JavaScript. PHP has many, many more features and functionally then JavaScript does, and it is much more secure. And I don’t understand how you can compare a language like PHP to an entire operating system.

5 Likes

It is absolutely my opinion, after waching the discussion. But the real my answer is after the feature function and secure can handle everything. It is time to say “it’s great” things. :smiley:

Ok um, this is going absolutely nowhere. The question was about re-writing URLs without htaccess, which we have established is not possible (to the extent that the user wants).

As for whether or not PHP is more feature rich than Javascript and secure, it depends, but that’s a discussion for another topic and another day.

You can always bring your thoughts to this topic, though:

As for our discussion, though, this is not relating to the original question anymore.

9 Likes

A post was merged into an existing topic: 10000 forum users celebration - special event

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.