.htaccess or PHP change url - php

Currently my .htaccess file reads:
DirectoryIndex dice.php
Dice.php is a loading page which has an iframe in (index.php) which eventually when finished loading breaks the iframe and fills the page. However it fills it as https://example.com/index.php in the url.
I want it to fill as https://example.com/play.
Anyone have any ideas?

Try adding this to your .htaccess file
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^play/?$ index.php [NC,L]

Related

Rewrite rule .htaccess not working with get PHP variables in ULR

I'm trying to make pretty URL for my gallery page.
Main page index.php gets url parameters tabl(table) and meno(name) to see which gallery to be visible.
I have a link to gallery.
'.$table.'
URL to show gallery.
https://onlinegallery.online/index.php?tabl=gallery&meno=admin
I need to get https://onlinegallery.online/gallery/admin
I spent a lot of time but all i write to .htaccess not working.
For example.
RewriteEngine On
RewriteRule ^tabl/meno/([0-9]+)/([^.]+)$ index.php?tabl=$1&meno=$2
May there be a problem with the php code inside index.php? Code is for redirect page if there is no variable inside url and is also the main page of my gallery page.
if(!isset($_GET['meno'])){
header('location: ' . 'https://onlinegallery.online/index.php?tabl=gallery&meno=admin');
exit;
}
Are you saying you want to visit URL:
https://onlinegallery.online/gallery/admin
to get:
https://onlinegallery.online/index.php?tabl=gallery&meno=admin
Where:
https://onlinegallery.online/[tabl]/[meno]
if that is the case
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/(.&)$ index.php?tabl=$1&meno=$2 [QSA,L]
Remember if are not using httpd.conf base configuration file, and you are using .htaccess file, .ht* configuration must be turn on (with rewrite module included), and your directory must have configuration of AllowOverride for accepting rewrite command too.
WORKS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/$ index.php?tabl=$1&meno=$2 [L]
Redirect /index.html /gallery/admin/
</IfModule>
On page where need to send variables to URL
<a href="https://onlinegallery.online/'.$table.'/'.$jmeno.'/"
On index.php i had to change all links to full URL
<script type="text/javascript" src="https://onlinegallery.online/js/full.js"></script>
Thank you all
https://onlinegallery.online/admin/gallery/

.htaccess - redirect everything

I am trying to get a landing page to work while I am doing scheduled updates on my site.
So basically all my original files will still exist in the directory including my index.php file but I've added another index1.html, so whenever I do an update I just want to be able to un-comment a line in my .htaccess file and everything will redirect to the landing page.
In my .htaccess file I have:
Options -MultiViews
RewriteEngine on
RewriteRule ^(.*)$ index1.html?path=$1 [L,NC,QSA]
This works for me in so far as any file or sub-directory I go to like example.com/whatever will redirect but example.com will still go to the original index.php which is what I want to be updating.
This line did exactly what I wanted:
DirectoryIndex index1.html

Redirecting from one page to another page on my website causes 404 error after using .htaccess file

Currently I'm working on a php blog.Where I have used .htaccess file to get clean url,here is the code.
RewriteEngine On
RewriteCond %{HTTPS} !=off
RewriteCond %{HTTP_HOST} ^mywebsitename\.com$
RewriteRule (.*) http://www.mywebsitename.com/$1 [R=301,L]
RewriteRule ^([0-9]+)/([a-zA-Z0-9_-]+)?$ post.php?post_id=$1&title=$2 [L]
RewriteRule ^(.+)/(admin|css|fonts|ico|include|js|images)/(.*)$ $2/$3 [L]
I got this code online.As I'm new to php and this htaccess thing,that's why I don't have much idea about it.
URL Before adding .htaccess file was:
[http://www.mywebsitename.com/post.php?post_id=12&title=post-title][1]
And,URL after adding .htaccess file:
http://www.mywebsitename.com/12/post-title
So rewriterule gave me the url that I want.But it has cause error in redirection of the page.Before using .htaccess file whenever i clicked on home button after visiting following url: http://www.mywebsitename.com/post.php?post_id=12&title=post-title
then URL redirected successfully to home page,that is:http://www.mywebsite.com/index.php page.
But now after using .htaccess file after visiting the same url it is redirecting like this:
http://www/mywebsitename.com/12/index.php
And now it is firing 404 page not found error.Because technically there is no such page present under 12 directory on server.
So after visiting the following link:http://www.mywebsitename.com/12/post-title
I want it to redirect properly as it was redirecting the pages before adding the .htaccess file.
Please guys help me out.
Thanks in advance.
Is the link http://www.mywebsitename.com/12/post-title your actual url. Is mywebsitename the your domain name? I think you should replace it with the actual domain name. It might just be a placeholder text

Change default page from index.php to index.html

Simple as the question. I want to change my website's default page from index.php to index.html. I don't know if my server (000webhost.com, while website is under development) uses Apache, but I've changed the .htaccess file, and added DirectoryIndex index.html index.php. Still not working, though.
When the website loads, it loads randomwebsitename12345.com. If I add /index.html to the string, then the page loads fine, as it should. If I remove the .php file from my server, then the website loads index.html.
Any ideas?
Why not just remove index.php from the .htaccess file?
You can use the following rewrite rule to set index.html as your homepage :
Add this before other rules in your htaccess :
RewriteEngine on
RewriteRule ^$ /index.html [L]

.htaccess allow image to display directly

I have many files including images, php& js scripts and subfolders.
I need to redirect to index.php for any uri using .htaccess.
for example:
www.example.com/test should be redirect to index.php
But images should not be redirected to index.php. Instead it should be printed directly in browser.
For example:
www.example.com/sample.jpg should display sample.jpg.
I am using following codes in .htaccess code:
RewriteEngine On
RewriteRule ^(.*)$ index.php
Can someone explain how to allow image to display?
Add conditions before your rule to skip image/css/js filesdirectories:
RewriteEngine On
RewriteRule !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ index.php [L,NC]

Categories