how to write .htaccess - .htaccess

I have tried but have not found proper solution for PHP .htaccess
Folder and files information:
.htaccess (on root)
/profile/personal.php
/profile/exam/exam_information.php
Sending URLs from (personal.php) and (exam_information.php)
/profile/2012/A1PPOAQU7
........\-------------/ // Friendly URL
/profile/exam/2012/A1PPOAQU7
.............\-------------/ // Friendly URL
I found, htaccess but it works for single URL only. Please check what is wrong in the code.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+)$ /profile/personal.php?pid=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ /profile/personal.php?pid=$1

Related

redirection with .htaccess (removing subfolder from URL and keep them into website)

I just want to redirect this kind of URL :
mydomain.fr/public/pages/project.php
To this kind of URL
mydomain.fr/project.php
I'm trying this kind of stuff in my .htaccess file
Redirect /public/pages/ http://mydomain.fr/
OR
RewriteEngine On
RewriteRule ^public/(.*)$ /$1 [L,NC,R=302]
(to remove just the 'public' folder).
Its working so when I click on a link of my website, the URL is redirected to what I want, but it broke the navigation. So I can't access my page (error like : The requested URL was not found on this server.) occured.
My question : How do I remove these subfolder in my URL without removing these subfolder into the server of my website ? I dont know if i'm clear, sorry my english is not perfect.
Thanks !
Have a good day

Rewrite engine not working using htaccess

I am trying to rewrite url using htaccess but it's saying 404.
RewriteEngine on
RewriteRule ^p/([a-z0-9])$ product1.php?pid=$1
It's not opening product1.php file.
You need to make sure your htaccess file and your product1.php file are in same folder. If not that it will give 404 errors.
If they are not present in same folder then you need to complete relative path from the path where your htaccess file is present like: eg: Let's say we have folder structure like:
/root/.htaccess
/root/singh/test/product1.php
So have your rules in following manner then:
RewriteEngine on
RewriteRule ^p/([a-z0-9])$ singh/test/product1.php?pid=$1 [NC,L]
Also apart from these put NC and L flags too in your rules to do case sensitive matching and making this condition's last rule here.

How to use htaccess file for subdirectory url

My problem is to redirect from subdirectory link to one file.
my current url
www.sample.com/stream/34/video.m3u8
www.sample.com/stream/35/video.m3u8
hope
www.sample.com/stream.php?param1=35&param2=video.m3u8
or
www.sample.com/stream/index.php?param1=35&param2=video.m3u8
Please save my life
You can do something like the following using mod_rewrite in the root .htaccess file in order to rewrite the request to /stream.php?param1=<id>&param2=<file>:
Options -MultiViews
RewriteEngine On
RewriteRule ^stream/(\d+)/([\w-]+\.\w{2,4})$ stream.php?param1=$1&param2=$2 [L]
This assumes that the <id> (2nd path segment) is entirely numeric and the 3rd path segment consists of <filename>.<ext>. You should restrict this to m3u8 if that is all you are expecting.

Replace the filename in the URI using htaccess

In my website, the main PHP script is named index.php. All URIs look similar to this:
index.php?section=FrontPage&l=ES_LA&view=multiple
In the htaccess file and using the mod_rewrite extension, I managed to remove the .php PHP extension, so the URI looks like this:
index?section=FrontPage&l=ES_LA&view=multiple
What I want to do now is to replace index.php with example in the path.
I've tried using:
RewriteRule ^example$ index.php
But when I try accessing example?section=FrontPage&l=ES_LA&view=multiple the server returns a 404 Not Found status code.
How can I fix this?

url rewriting asp .htaccess file

I just moved my website (asp.net) to the live environment. I realized they are running IIS 6 so all my nice and clean url rewriting doesn't work anymore. I was trying to implement URL rewriting using the .htaccess file.
I want to rewrite:
www.amicobio.co.uk/Menu.aspx to www.amicobio.co.uk/Food-Menu
So in .htaccess I set:
CaseInsensitive On
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^Food-Menu$ Menu.aspx
But it doesn't work it says:
The requested URL
/a/m/amicobio.co.uk/public/Menu.aspx
was not found on this server.
Obviously the path is wrong but what is /a/m/ and how do I fix it? All the files in amicobio.co.uk/public/
Thanks.
I found the solution
it was
RewriteRule ^Food-Menu /Menu.aspx
in stead of
RewriteRule ^Food-Menu$ Menu.aspx

Resources