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]
Related
I'm struggling pretty hard with .htaccess. Even though I looked up quite a few solutions here, I couldn't get to setup the following:
I have a file called index.php. Inside the index.php I have a link like
Post
Clicking the link, should lead to a file in the same directory called post.php. Inside the post.php I'm grabbing the id through $GET['id'].
But I still like to display post/12345678901 as the URL.
I already tried editing the .htaccess but clicking the links leads to a 404.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^post/([^/]+) /post.php?id=$1
You have a RewriteRule but you probably need a ReWriteCondition to go with it else this rewrite will be applied to every call to a page on the apache.
Options +FollowSymlinks
RewriteEngine on
# Not a file
RewriteCond %{REQUEST_FILENAME} !-f
# not a directory
RewriteCond %{REQUEST_FILENAME} !-d
# Edited to show root location of files.
# also added NoCaseSensitivity flag.
RewriteRule ^post/([0-9]+)/? /post.php?id=$1 [NC]
Also remove the first / in the second part of the RewriteRule because that will be domain.com/post.php which might not be your actual file location.
Your HTML appears to be showing relative filepathing which is not a good idea and might come back to bite you in the future, As a recommendation every URL on the same domain on your HTML should start with a / so;
Post
Which can then be manipulated by the .htaccess to go where you need, even in another folder (not the base).
I have a single point of entry on my website
mysite.com/admin/index.php?View=List&Model=User
All access to the DB/application is through this index.php file.
I would like to clean my URL from what is shown above to.
mysite.com/admin/List/User
The idea is to remove the key 'Model and 'View'.
I have found this link that looks very similar.
PHP/Apache: Rewrite rules with .htaccess
in htaccess file insert this code :
RewriteEngine On
RewriteRule ^admin/([^/]*)/([^/]*)$ /admin/index.php?View=$1&Model=$2 [L]
The rewritten URL:
http://mysite.com/admin/List/User
this site very useful for generate rewrite URL
http://www.generateit.net/mod-rewrite/
Create a file named .htaccess in your web root if you haven't already got one with the following:
# Turn the rewrite engine on (skip this if already done)
RewriteEngine On
# Redirect admin/List/User/ to admin/index.php?View=List&Model=User
RewriteRule ^admin/([^/.]+)/([^/.]+)/?$ admin/index.php?View=$1&Model=$2 [L]
This might work:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^admin/([^/]+)/([^/]+) /index.php?View=$1&Model=$2 [NC]
Add to .htaccess in the root folder of your website.
I have a uri: www.domain.com/leasing/properties/
Within that directory, I created a file .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ index.php?uri=$1 [L,QSA]
What I want, is that regardless of that users type after properties/ (Ej. www.domain.com/leasing/properties/somethigelse/I-do-not.care/what##$%they\type) to be handled by www.domain.com/leasing/properties/index.php
I do not need structure or anything else. index.php will grab $_REQUEST['uri'] and check against a database. So, again, I do not care what's typed after www.domain.com/leasing/properties/ so long index.php can get the URI and handle an action according to $_REQUEST['uri']
I want the address bar to not not change. Whatever a user types, to remain the same.
The current file is giving me a 404 error.
PS. I know close to nothing about Apache .htaccess
Create a .htaccess file with the following:
RewriteEngine On
RewriteRule ^([^/]+)(.*)$ /leasing/properties/ [R]
And place it within /leasing/properties/ folder.
RewriteEngine on
RewriteRule ^/leasing/properties/(.*)$ /leasing/properties/index.php [L,QSA]
If that does not work, your Apache server may not be configured to allow .htaccess files.
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
I would like to take requests for /somefolder/style.css and handle them with /somefolder/program.php
So, I put the following in my .htaccess file:
rewriteengine on
rewriterule ^style.css$ program.php?css=1 [R=302,L]
The result is that instead of redirecting to /somefolder/program.php, the server tries to redirect to:
/var/www/html/somefolder/program.php?css=1
How can I get rid of the /var/www/html/ in the redirect? I thought that since I just entered program.php in the .htaccess that it would default to the same folder.
Since this is a generic script that I will use in many places, I would like to avoid using rewritebase to specify the folder I'm in -- the .htaccess has to work in any folder without being modified.
Leave the R flag away and you will get an internal redirect:
RewriteRule ^style\.css$ program.php?css=1 [L]
Otherwise specify the full URL path you want to redirect to externally:
RewriteRule ^style\.css$ /program.php?css=1 [R=302,L]
Or for any arbitrary folder:
RewriteCond %{REQUEST_URI} (.*)/style\.css$
RewriteRule ^style\.css$ %1/program.php?css=1 [R=302,L]
I think the problem is that you are missing a ReWrite base statement.
Also the I would put the .htaccess file in the root directory of your site. That way you don't have to copy an .htacess file into every new directory you create. What if you want to change the name of your php file? You'd have to change every .htaccess file.
This is how I would redirect www.mydomain.com/orange/style.css to www.mydomain.com/orange/program.php?css=1 using generic rules:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/style\.css$ $1/program.php?css=1 [L]