I had to add a PHP file within a Wordpress installation. I have created a subfolder and the file works fine, but I need to make it "pretty" according to Wordpress permalinks style.
In few words:
https://example.com/php/partners.php
must become https://example.com/our-partners/
How can I do it? Where should I place the .htaccess file? In the root as it is now or will I need another one in "php" folder?
Thank you!!!
Max
Easy way make wordpress template in theme.
Put below code at the top of the php file in comments
<?php /* Template Name: logicdigger */ ?>
Then move your file in to your theme.
Go to add page and create new page then select template from right side of your screen. THAT'S ALL
Complete article here
You will edit the existing .htaccess file in the root. Something like this should work:
RewriteEngine on
RewriteRule ^/?our-partners/?$ /php/partners.php
Requests to /our-partners and /our-partners/ (with or without trailing slash) will point to /php/partners.php. This also allows for query params in the URL if needed: /our-partners?foo=bar
This requires mod_rewrite to be enabled in apache. The docs for RewriteRule can be found here
Related
I have a very peculiar problem. Formerly, I was using Wordpress and I have a link that has a path of http://www.acetraining.com.sg/index.php/contact-us/.
I have just reverted the website to a non-Wordpress and have a static link of http://www.acetraining.com.sg/contact_us.html. How is it possible for me to redirect the old path to this new path? I already have a redirector script and I know I have to place this code :
<meta http-equiv="refresh" content="0; url=http://example.com/" />
to the head region of a html page. What I have done is that I've created an index.php as a folder name and another contact-us as a subfolder and then I created an index.html file within that but it does not work at all.
Any suggestions anyone?
Good morning!
I think that using meta tag for redirection will not good for your SEO. As it is a definite URL moving, I suggest you the header 301 (Redirect Permanent). You can use this by creating a .htaccess file in public_html (or your website public root directory) and put on something like this :
RedirectPermanent /index.php/contact-us/ http://www.acetraining.com.sg/contact_us.html
Hope this may help you.
If you don't have a .htaccess file in your server root!
Create an empty text file using a text editor such as notepad, and save it as htaccess.txt and add the code blow.
Options +FollowSymLinks
RewriteEngine On
# Redirect old file path to new file path
Redirect index.php/contact-us http://www.acetraining.com.sg/contact_us.html
NOTE:
The reason you should save the file as htaccess.txt is because many operating systems and FTP applications are unable to read or view .htaccess files by default. Once uploaded to the server you can rename the file to .htaccess
hopefully it will fix the redirection for you.
I want to map URL in my localhost XAMPP into custom files.
For example:
localhost/index.php --> d:\xampp\htdocs\index.php (default)
localhost/normal/data.php --> d:\xampp\htdocs\normal\data.php (default)
localhost/view/userinfo.php --> d:\xampp\htdocs\view.php?p=userinfo (custom)
localhost/view/welcome.php --> d:\xampp\htdocs\view.php?p=welcome (custom)
So, basically, all URL that goes into inside view path will be mapped to view.php files with the filename.php (minus the .php) as its query parameter. There's actually no physical folder view, and no physical files userinfo.php and welcome.php inside the folder.
The reason that I need to do this is that so I can pass all the pages that viewing data into an "application frame" that will wrap the page with header, menu, and footer, and I don't need to give header, menu, and footer call in each page. I might have the actual files userinfo.php that I can $include_once, or I might not (I can just generate it from within the view.php), but hey, that's one of the power of this kind of framework, right? And, if someday I need to change this structure, I can change it from just within one file (view.php), not all.
Can I do this in PHP and XAMPP? How? I've noticed that some website seems to used this practice (URL which have no actual files or even path at all), but when I try to read tutorial for it, I got confused.
URL mapping in PHP?
The accepted answer listed 3 links to learn about URL rewriting. Mostly they're written for Apache in Linux, and mostly they pull all the possible scenario and configuration that I got confused which one I really need with all those long documents and technical jargon. I need just the practical step of my specific problem, and then, I will be able to start from there to explore myself if I have more advanced needs. Please help.
if you do want to go down the mod rewrite route adding the following to an .htaccess file in the site root should do it. You will need to make sure mod rewrite is on for XAMPP and I can't help you there I'm afraid. As you can see it rewrites the url, not the windows filename - so it would work on any OS.
The ([a-z]*) means it will take any filename.php with lowercase letters and redirect to /view.php?p=$1 where the $1 will be replaced by filename.
the [L,R] (L means last rule so stop processing if any more are reached, and the R means redirect (it will change the url in the browser). Use P instead to reverse Proxy (the user will still see the url they requested but the server will serve the correct file) - This will require mod_proxy as well.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^view/
RewriteRule ^view/([a-z]*).php$ /view.php?p=$1 [L,R]
</IfModule>
XAMPP uses apache so the rewrites would work the same in Windows as they do in Linux. You could place a .htaccess in the site root directory with some rewrite rules.
However, using PHP
in d:\xampp\htdocs\view\userinfo.php you could include the line
<?php
header('Location: http://localhost/view.php?p=userinfo');
?>
But this must be before any thing is echoed to the screen (even whitespace).
You can use the Apache module mod_rewrite to edit requests before they hit PHP. You want to put something like the following in a .htaccess file in your htdocs directory.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^view/
RewriteRule ^view/(.*)\.php.*$ view.php?p=$1 [L,QSA]
QSA means Query String Append. This means that if there are any GET parameters set on the original request they will be appended to the end of the new request too.
Note that this assumes that Apache is configured with AllowOverride enabled and the mod_rewrite module loaded.
I'm not the best with mod rewrite so if anybody can help me out here that would be great.
I'm using a markdown processor script and it's using rewrite to grab any files that end with a markdown file type. However, I'd like this script to grab any files within a folder, rather than any files that end with the markdown file type.
Here's the htaccess:
# display Markdown as HTML by default
RewriteEngine on
RewriteRule .+\.(markdown|mdown|md|mkd)$ /static/includes/markdown/render.php
RewriteRule .+\.(markdown|mdown|md|mkd)\-text$ /static/includes/markdown/render.php [L]
Is there a way to grab all files within a folder called (let's say) "folder" and eliminate the file type on the end?
So maybe have a URL like
website.com/home
that actually is
website.com/home.md
and is processed with the markdown script?
Hope this makes sense.
The re-write module and it's .htaccess files actually work on a per folder basis. Usually one would have a main .htaccess file in the web root of a site/server. However you can add numerous .htaccess files throughout your site's folder structure giving each individual folder specific rules.
All you would have to do is add another .htaccess file to your markdown folder and enable it to parse URL's without file extensions, forwarding it to a script which will be able to detect what original file was requested -
RewriteEngine on
RewriteRule ^(.*)$ /static/includes/markdown/render.php?file=$1 [L,QSA]
Basically what is happening here is that any file requested within this folder will be passed through your render.php file.
Now in your render.php file, you would have a $_GET parameter of file containing the original URL. For a url of http://example.com/markdown/foo, your render.php would have foo in the file parameter -
/static/includes/markdown/render.php?file=foo
If you set the correct headers in render.php it will be able to print out any format of file, hiding it's extension in a "fake" URL.
I'm wanting to upload a standard php file to the root of my website which also has WordPress installed. I think there is something with the .htaccess file that's not letting me access a file even if it exists but instead passing every call through to WordPress's index.php file which in turn throws me to a WordPress 'page can't be found'.
I've looked through similar questions on here with no avail.
What I'm thinking is there is something funky going on, or I need to modify my .htaccess from the standard one that ships with WordPress or ??
Any help is appreciated!!
Thanks in advance,
Mark
If your file is called foo.php, add this line to your .htaccess file, directly below RewriteEngine on:
RewriteRule ^foo.php$ - [L]
Add a RewriteCond with the name of the file you want to access, that checks if the current file is the file that you want to access.
I am building a site that will (obvisouly) have a front end public portion that I want to drive with Concrete5, but then it will also have a members section that I would like to build with Code Igniter.
Does anyone have any idea how I could do that?
I guess I could just throw the Code Igniter code into a sub directory, but would I run into any issues with that?
i can't see why not.
As you suggested a separate folder on the site would be one solution.
(you might have to tweak the .htaccess file (if you are using one) to ignore the other cms/framework
Another solution would be to have separate subdomains,
eg example.com and members.example.com
The answer, since the OP hasn't posted it, is to change the .htaccess rule:
RewriteBase /
to:
RewriteBase /foo/
where foo is your subdirectory that the index.php and CI reside. This .htaccess should also be in the same folder as the CI index.php. Works like a charm. Also don't forget to add the subdirectory to the base_url config setting.
I ended up using a sub directory for Code Igniter. I had to change the .htaccess file and Mod_Rewrite rules for apache in order for the Code Igniter "pretty" URLs to work correctly.
I will post the code later if I remember.