Remove .php from action link in html - php

I want to remove .php from the link in form's action attribute.
the link is:
localhost/shopproject/MassUpload/create_excel.php/createExcel.
I've tried using .htaccess from other questions, but I find only the way to remove .php at the very end of the link e.g
localhost/shopproject/MassUpload/create_excel.php/createExcel.php
to
localhost/shopproject/MassUpload/create_excel.php/createExcel.
I wonder how can I make the link to:
localhost/shopproject/MassUpload/create_excel/createExcel
If it isn't possible is there a better way so that I can hide the usage of create_excel.php from a user?
Thank you for the help

if you ONLY need it for this specific form...
RewriteEngine ON
RewriteRule ^create_excel/createExcel$ create_excel.php/createExcel.php
or if you have a lot of different forms using something like this...
RewriteEngine ON
RewriteRule ^(.*)/(.*)$ $1.php/$2.php
Please note, you probably need to add the correct path that your live website uses.
I think something like this (if you added in proper paths) may be able to help you. I haven't done rewrites in a while, but this would say /anything/whatever is the same as /anything.php/whatever.php
so this would be like saying that /create_excel.php/createExcel.php can be accessed through create_excel/createExcel
If this doesn't work, or you can't create something similar in .htaccess, please try the following I suppose...
create_excel/createExcel/index.php
This would allow you to use site.com/create_excel/createExcel/ as a link, because index.php is automatically used (and not displayed in URL bar) when you set up a folder for this.
If you are using some sort of third party library or system, I highly recommend not creating a custom folder like this.

Related

htaccess change requested filename

I need to do this using htaccess
When a request is made for http://www.example.com/home, it should (internally)load the page http://www.example.com/home_st.php
Similarly when a request is made to other link called products (http://www.example.com/products), it should (internally)load http://www.example.com/products_st.php
In short what it is doing is appending "_st.php" and loading that URL. But one thing I do not want is if the user directly types http://www.example.com/home_st.php or http://www.example.com/products_st.php in the browser, it should show 404 / Page not found error
I have few other pages in that folder and I want those pages to behave in this manner. I understand the htaccess should have something like this
Turn on the rewrite
Forbid access if the URL is called with page names like home_st.php, products_st.php etc.
If it's "home" or "products", then rewrite(append?) it to home_st.php and products_st.php respectively. I have other files too while need to follow the same
P.N: My URL should not show the actual filename, for example home_st.php, products_st.php etc. It should only show as http://www.example.com/home, http://www.example.com/products etc
htaccess and regex is not something that I am well acquainted with. Any help would be great. Thanks
You want to be able to re-write URL's
This has been written before but i'll say it again.
You want to use the Htaccess file and the re-write rule.
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^pet-care/?$ pet_care_info_01_02_2008.php [NC,L] # Handle requests for "pet-care"
This will make this url: http://www.pets.com/pet_care_info_07_07_2008.php
Look like this: http://www.pets.com/pet-care/
Links to more information: How to make Clean URLs
and for the webpage I used to reference this information from: https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
To get your pages set the way you want them, I would advise that you read the two articals and try get what you are looking for.
If you need some specific help with doing this, ask.
Hope that helps.

PHP - User Profile URL From Ugly URL

Alright, I usually try to figure things out on my own, but I am stumbled. I am currently making a PHP registration/login/profile system with PHP and SQL. I am 97% finished, but I would like some help with the users' profiles.
I currently have a form where you can search for users. This is a GET form that links to "www.example.com/profiles.php?username=." I would like for it so that I can link it to something like "www.example.com/user/" or "www.example.com/profile/." I would also like the functionality of going directly to the "user/" URL.
I am sure there are rewrite rules to do this, and I have tried many. I still seem to have trouble getting it to work. Any help? Thanks in advance.
Here is my current .htaccess file (doesn't work):
RewriteEngine On
RewriteRule ^user/([^/]*)\.php$ /profile.php?username=$1 [L]
If this htaccess does work, what should I be linking to? Because currently, linking to the "/profile.php?username=" doesn't do anything.
Again, to clarify, I want the output from the GET form to be able to link to www.example.com/profile/USERNAME or www.example.com/user/USERNAME. I would also like for the user to access their profile by typing www.example.com/profile/USERNAME.

.htaccess url rewrites for white label sites

I'm building a simple site that will only have a homepage and a contact page and wondered if I could use .htaccess to rewrite the urls for different companies.
So for example if I go to website.com/companyname-contact/ it will display that url in the browser bar but actually load a generic contact.php page, I can then use php to pull in the correct contact details for that specific companyname.
This would need to work for different company names (e.g. website.com/anothercompany-contact/) but only work for an array of approved company names.
I realise this may not be possible but I thought I'd ask because i spent about 4 hours this morning Googleing it with no real progress.
Thanks
Unless you want to manually list the approved company names in your .htaccess file (which looks UGLY) I'd suggest this:
RewriteEngine On
RewriteRule (.*)-contact$ /contact.php?company_name=$1 [L,QSA,NC]
and then in your contact.php
determine if valid company name - check db or whatever method you are using. (Make sure to escape the input)
if not valid you have a couple options:
redir to your default 404 page
issue an intelligent warning page (ie include suggestions for alternate spelling that is in the db) and set a 404 header. (better IMO)
if similar company name in the db possibly redirect to that with a note at the top of the page
Yes you can. You need to enable the rewrite engine, and then you will be able to use regular expressions to accomplish what you're trying to do.
This is an example of what your htaccess could like:
RewriteEngine On
RewriteRule ^contact/([A-Za-z0-9-]+)/?$ contact.php?company=$1 [NC,L]

I need suggestion for using a .htaccess in Code Igniter framework

My old website doesn't use a framework and the .htaccess worked fine, take a look at my .htaccess code below:
RewriteRule ^([a-zA-Z0-9_-]+)\.html solution.php?solution=$1 [L]
So the point there is that if it detects '.html' in the url, then the user is redirected to a PHP page passing any GET parameter.
Recently, I have converted my website to use the code igniter framework, so I have converted my .htaccess code to something below:
RewriteRule ^([a-zA-Z0-9_-]+)\.html index.php/solution/index/$1 [L]
I end up getting a page not found. However, if I still manually type
http://myhost/index.php/solution/index/xxx
then it works, but if I type
http://myhost/xxx.html
then it doesn't. My objective here is to maintain the original URL because it is indexed by Google and I do not want the previous visitors of my website to be getting a 'page not found' for my old links.
I need a fix or suggestion that might help. Looking forward to your response. Thanks.
Looks like you missed a lot of stuff while converting your website to use CI. Read about URL suffixes and also note you can use routes to redirect anything you can't handle normally using controllers.
You also need to modify your .htaccess to get rid of index.php since only modifying the config file won't work - there are a lot of resources about that, like this one.
Follow the codeigniter user guide: http://ellislab.com/codeigniter/user-guide/general/urls.html
Specially in following section:
Removing the index.php file
Adding a URL Suffix
If still having problem then check this wiki:
https://github.com/EllisLab/CodeIgniter/wiki/Removing-index.php-in-codeigniter-xampp-for-windows
or
How do I write a .htaccess file to make CodeIgniters URL routing work?

How would my web page examples look like before mod rewrite when using PHP

I want to display all my tags on one web page for example, www.example.com/tags/ and then when some one
clicks on one of the tags I want to display all the posts related to that tag on another web page for example, www.example.com/tags/clicked-tag/
how would I be able to do this since it really would not be a good idea to create a web page for each tag?
I will be creating an index.php page for the tags folder www.example.com/tags/.
But how would I be able to display the posts related to that tag on another page for example, www.example.com/tags/clicked-tag/?
Mod_rewrite for generating get variable in "nice" form
You have to add mysql field called "tag" or something
One possibility is to use a rewrite rule. Create a PHP file named say "details.php" inside the tag folder.
Then, in httpd.conf:
RewriteRule /tags/([^/]+)/?$ /tags/details.php?tag=$1 [B,L]
or, if you must, in a .htaccess file inside /tags:
RewriteCond $1 !=details.php
RewriteRule ([^/]+)/?$ details.php?tag=$1 [B]
Another possibility would be to activate the option MultiViews and serve all requests to /tags/* from a file named tags.php in the root (using the path info to determine what to show).
Am I missing something here? You seem to want to display all posts for a given tag <my_tag> on the page www.example.com/tags/clicked-tag.php?
So, can't your tags link to www.example.com/tags/clicked-tag?tag=<tag_name>, where <tag_name> is different for each tag, obviously, and then www.example.com/tags/clicked-tag.php simply look at a variable $_GET["tag"]?
That seems the way to do it in PHP, but since others are giving rewrite answers I fear that I may have misunderstood the question. If so, maybe you could clarify?
i want all the tags to have their own unique file name like www.example.com/tags/tag1 www.example.com/tags/tag2 www.example.com/tags/tag3 and so on - thanks for the clarification.
How about ... mmmm ... all links on the first page lead to an intermediate page which the user will never see ... www.example.com/tags/clicked-tag.php for example, and that does something like
if file www.example.com/tags/<tag> not exists then crete it
header("Location: www.example.com/tags/<tag>");
and each page includes a common file with a function which takes as a paramater and build the output page ...
That would do it, wouldn't it?

Categories