Converting .php link with variable to .html - php

I I am trying to convert php links with variables to html link (like on SMF) so increase seo of my site,
My links are like:
http://site.com/pages/page1.php?v1=var1&v2=var2&v3=var3&v4=var4
or:
http://site.com/pages/?v1=var1&v2=var2&v3=var3&v4=var4
I need it to look like this:
http://site.com/pages/page1.var1.var2.var3.var4.html
or
http://site.com/pages/var1.var2.var3.var4.html
or
http://site.com/page.php/var1,var2.var3.var4.html
linke in SMF forums:
http://forum.com/index.php/topic,9197.0.html
How to do that and alos be able to GET those variable values?

You just need to learn how to implement URL rewriting. I know PHP runs on Windows in IIS, but I'm going to go ahead and assume you are probably running Apache. Just read up on redirecting with .htaccess files and mod_rewrite. There's also something similar (that, alas, you have to pay for) called ISAPI Rewrite for windows servers which I've used plenty of times. And if you don't want to use a third party plugin and you have server 2008, the wizards for IIS do a pretty decent job and they just modify your web.config file directly to do the redirects.

you might want to try to research about URL encoding that's what i know if you like to change how your links display the url... hope my answer is enough :)
http://www.jaywebtechnologies.co.cc

I see that your issue is already solved (for Linux).
If anyone has the same problem with a Windows Server, you can use Ionics ISAPI Rewrite Filter
http://iirf.codeplex.com/
I've been using it for years now, and it works perfectly. Just wanted to post it here in case anybody needs it.

Related

How To Rewrite URL in PHP Only?

I have a MVC (Model, View, Controller) structured site that I'm thinking about. It's hosted on smallbusiness.yahoo.com. (Apache) They limit the hosting to php (and mysql), and there's no way I can edit the server configurations. That means no .htaccess files! I have searched for the solution for a long time, but they all involve editing the server configurations. I am looking for a way to rewrite URLs with only php itself.
I want to do URL rewriting so that the controller(s) can receive parameters through the URL. I know Codeigniter does this, but I do want to LEARN how it does it.
For example, something like this:
example.com/page.php?page=whatever
turns into
example.com/page/whatever OR
example.com/whatever
I've seen some examples with $_SERVER['PATH_INFO'], but I don't understand what that does.
I've tried
$_SERVER['PATH_INFO'] = '/';
But that did nothing...
Help would be greatly appreciated!!
This is the closest thing I could find. Strictly speaking, even WordPress modifies the .htaccess to allow their own module to manage the rewriting. I find it odd that they would completely disallow all .htaccess changes. Have you given it a try? Even ASP.NET requires a web.config modification to use rewrites.
http://pure-essence.net/2007/06/29/simple-php-path-rewrite/
Obviously the last solution wouldn't help if .htaccess is disallowed entirely, but that's rarely the case where you can actually use PHP. I can see them disallowing overrides, but that usually only applies to things like indexes and directory options.
I advise you to take a look at this, maybe it could help you.

Simplifying URL without using .htaccess

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 :). )

What is a good way to set up a site template with PHP on IIS6?

I am not very experienced with PHP. I have a site I'm maintaining that is on IIS6 using PHP. Right now it is using include files and querystrings to server up content.
For example:
http://mysite/index.php?maincontent=services&subcontent=service1&nav=subnav1
We want to change the site so that URLs look more like (for example):
http://mysite/commercial-services.php
But, I don't want to duplicate code and include files in the 30+ files of the web site.
Is there an easy way with php to have a template that keeps the short urls but allows you to use the same layout file for multiple pages?
I do mostly .net web sites so I guess what I'm looking for is something comparable to asp.net master pages.
I also looked at php frameworks, namely codeigniter. However, that by default leaves an index.php in the middle of the url. From what I read we would need to use some type of isapi rewrite to get rid of that. I can't do that because I don't have access to the server and they don't want to install things on the server.
Is there anything simple we can use or are we limited to using includes?
Update:
For this I ended up converting the site to .net. It was much faster and easier (for me) to do than figure out how to set up something with PHP.
I'd say look at rewrites not frameworks if all you want to do is change the urls, that way you backend php can stay the same but you still get the nice urls.
There's loads of tutorials, quick google gave me:
http://articles.sitepoint.com/article/guide-url-rewriting

Apaches mod_rewrite VS. PHP routing?

for some days now I have been trying to make a simple mod_rewrite rule to create friendly URLs, my web host have mod_rewrite enabled but I just can't get it to work.
All the next questions where posted by me:
.htacces to create friendly URLs
Friendly URLs with .htaccess
.htacces NOT working…
None of the answers worked, so I'm thinking now using simple php routing instead and I wanted to know if there is a big performance or SEO difference between the two. And if there is, maybe you know how to fix the mod_rewrite problems posted in my questions.
Thanks.
If you're using PHP routing for PHP files only, it would be no problem performance-wise: The interpreter will get started anyway, a new process started, memory allocated etc.
But if you are planning to route requests for static resources like images and style sheets as well, however, don't use PHP routing under any circumstance. It's way too resource-intensive and not what PHP was built for.
I'd say mod_rewrite is the better, leaner solution and it's worth trying to figure it out.
I prefer routing that kicks in when the requested file doesn't exist, like this in Lighttpd:
server.error-handler-404 = "/index.php"
Provided you find out how to do this in Apache, your script would be more cross webserver compatible, since Apache's mod_rewrite conditions in .htaccess won't work on Lighttpd.

How to hide the url in php

Is it possible to hide the the url in the address bar of the web browser so that it won't necessarily match the location of the files.
For example, this url:
http://localhost/exp/regstuds.php
You will always know by looking where to find the files in the computer.
Is it possible to distort or disarrange or hide the url in such a way that the location of the files will not be revealed
Yes, if you're using Apache look into using mod_rewrite. There are similar rewrite modules for pretty much all other web servers too.
I hope your sole motivation for doing this is not "security through obscurity". Because if it is, you should probably stop and spend more time on something more effective.
If you are hosting your php on an Apache server, you probably have the ability to use the mod_rewrite utility. You can do this be adding rules to your .htaccess file...
RewriteEngine on
RewriteRule ^RegStuds/ regstuds.php
This would cause http://localhost/RegStuds/ to actually render regstuds.php, but without ever displaying it in the address bar.
If you are on IIS, you can perform the same function using an ISAPI Rewrite Filter.
If you don't have mod_rewrite or an ISAPI Rewrite Filter, you can get a similar result using a folder structure, so you would have a physical path of RegStuds/index.php - and you would never need to link to "index.php" as it is the default file. This is the least recommended way of doing it.
No its not.
Each bit of functionality must have a unique identifier (URI) so that the request is routed to the right bit of code. The mapping can be non-linear using all sorts of tricks - mod_rewrite, front controller, content negotiation...but this is just obscuring what's really going on.
You can fudge what appears in the address bar on the browser by using a front-controller architecture and using forms / POSTs for every request but this is going to get very messy, very quickly.
Perhaps if you were to explain why you wanted to do this we might be able to come up with a better solution.
C.

Categories