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

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/

Related

.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

rewriting .htaccess to hide real page path

I want to hide real page path using RewriteCond inside .htaccess
As i wanted to give my user download link of a perticular file. Suppose
www.mnc.com/myBook.pdf
www.mnc.com/youBook.pdf
Now this myBook and youBook is inside of public/pdfdirectory. As you can see that i tried to hide the directory from Url.
Now how i set the .htaccess rule so that when a user tried to access www.mnc.com/myBook.pdf it will automatically set the url path to www.mnc.com/pdf/myBook.pdf so that directory could be hide in browser path.
You are asking for rewrite I assume and assuming you are using rules in root dir try with below,
RewriteEngine On
RewriteRule ^([^/]+)\.pdf$ /mnc/pdf/$1.pdf [L]
Try this simple one.
For redirection of such requests like
localhost/mnc/public/youBook.pdf to
localhost/mnc/public/pdf/youBook.pdf
1. if REQUEST_URI ends with .pdf
2. Flags L,NC,END is last rewrite,non case sensitive and for ending further redirection respectively.
Note: If you don't use END flag it will case loop of rewriting.
.htaccess code: You can try this here
RewriteEngine on
Options -MultiViews
RewriteCond %{REQUEST_URI} \.pdf$
RewriteRule ^(.*)\/([\w]+\.pdf)$ $1/pdf/$2 [L,NC,END]

.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]

.htaccess or PHP change url

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]

htaccess mod_rewrite help

i have a domain with a website in a folder.
i.e
http://domain.com.au/website/page.php
i only have access to .htaccess files to make the rules.
i would like my url to look like this..
http://domain.com.au/page
so in essence i want to drop the subfolder its sitting in, and the php extention.
All links in my php are structured like this though
page link
this is the same for js and css. they are all referenced from the 'website' folder.
will the rewrite mean i have to change all my links?
priority is dropping the folder from the url, not so much the php extension.
1) You could move all the files to the root web directory and run the website from there.
2) You would have to manually modify every link to remove the website directory from the beginning and then use the .htaccess file to redirect the pages back to the appropriate page. If you're going to do it this way, you might as well remove the PHP extension...
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^domain.com.au$ [NC]
RewriteRule ^(.*)/ website/$1.php [L]
You may have to modify the website/$1.php part to include your entire root directory in some cases, but that should work as long as the .htaccess file is in the root web directory. That will redirect any page in the form 'http://domain.com.au/page' to 'http://domain.com.au/website/page.php' while keeping the URL the same in the address bar.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^page\_one/(.*)/([0-9]{1,6})/?$ webroot/products/products/view/$2 [L]
</IfModule>
this htaccess code redirects all trafic from www.domain.com/page_one/anything/numeral
to the page www.domain.com/webroot/products/products/view/same numeral
for your example, something like
RewriteRule ^page?$ website/page.php$2 [L]
note, this works for "page" as a string, if you need other functions , change it
for more insight, you might want to take a look at this link :
http://www.javascriptkit.com/howto/htaccess.shtml

Categories