User friendly URL through .htaccess - .htaccess

My url looks like -
http://localhost/user_notes/?id=1234.
I want to be turn it into user friendly url like
http://localhost/user_notes/1234
My .htaccess file looks like -
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
RewriteRule ^(.+)$ /user_notes/?id=$1
</IfModule>
The problem is with RewriteRule ^(.+)$ /user_notes/?id=$1
For more info see my directory structure
Note : In my directory structure there is also a public folder. But I can access files without including public in URL through htaccess file (line 3).

Could you please place these rules at top of your htaccess file(I hope there are NO redirect rules for https in your htaccess file). Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^ public%{REQUEST_URI} [L]
RewriteRule ^(user_notes)/(.*)/?$ $1/?id=$2 [NC,L]

Related

Two different pages/files in the .htaccess

I'm getting to know more about .htaccess, Apache & httpd config file. I have 2 files:
index.php
page.php
Both in the same folder
I already succeed to rewrite the index.php?site= to example.com/sitename. But when I try to add a rewrite which has to look like example.com/sitename/article/2 which redirects to page.php?site=sitename&page=pageid,
the rewrite does not work. I think this is because of the previous redirect example.com/sitename
But I like to have them both in my .htaccess file.
My current code is
RewriteEngine On
RewriteRule ^(admin)($|/) - [L]
RewriteRule ^([a-zA-Z0-9-/+]+)$ index.php?site=/$1 [L,QSA]
RewriteEngine On
RewriteRule ^(admin)($|/) - [L]
RewriteRule ^([a-zA-Z0-9-/+]+)$ index.php?site=/$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9-/+]+)$ index.php?site=/$1/Article/&page=$2 [L,QSA]
As you can see in the last code example I added has to go to:
example.com/Sitename/Article/2

Rewrite htaccess url and remove extension

I'm trying to rewrite and remove extension
http://www.example.com/pages/cart.php
to
http://www.example.com/cart
My htaccess file is located in the public folder.
RewriteEngine On
RewriteRule (.*) pages/$1 [L]
With your shown attempts, please try following htaccess Rules. Make sure you keep your htaccess file along with pages folder(not inside it).
Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/pages/(cart)\.php\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteRule ^(.*)/?$ pages/$1.php [L]

How do I redirect in .htaccess file without changing URL

I want to redirect several pages to a PHP page with GET variables. However, when I try to use an .htaccess file, it redirects but changes the URL. I don't want it to change the URL structure when redirecting. How would I do this?
For example, I want to redirect /fly-snooze-cruise to http://example.com/package_listing.php?package-type=fly-snooze-cruise
and /fly-snooze-cruise/orlando-airport to http://example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport
Here is my .htaccess code:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^fly-snooze-cruise$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise [L]
RewriteRule ^fly-snooze-cruise/orlando-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport [L]
RewriteRule ^fly-snooze-cruise/orlando-sanford-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-sanford-airport [L]
RewriteRule ^fly-snooze-cruise/melbourne-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=melbourne-airport [L]
RewriteRule ^snooze-park-cruise$ http://www.example.com/package_listing.php?package-type=snooze-park-cruise [L]

Redirect url with .htaccess

I m sure that many people will say that this is duplicated but I try everything from other "Question"`s and nothings work for me.
The problem is that I move my project to the web server.
In this server I have folder "public_html" where I but my project Symfony.
Now to enter on my project I must write the following url: www.mydomain.com/Symfony/web/*
But I want to write a Rewrite Rule which will redirect from www.mydomain.com/Symfony/web/* to
www.mydomain.com/home/*.
To do this I try on 2 different ways with many combination of ReWrite rule.
In my public_html I create a .htaccess folder
I edit the .htaccess in Symfony/web folder
I add the following rule in both file but without success
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Symfony/web/(.*)$ www.mydomain.com/home/$1 [L,R=301]
Unfortunately without success. What I`m doing wrong?
My htaccess file look like
And all the time Error 404 Object not found
Symfony/web/.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteRule ^home/(.*)$ $1 [L,NC]
</IfModule>
It`s redirecting me but I receive again Object not found :(
I delete the .htaccess in public_html folder which is the root one for my server
public_html\.htaccess
RewriteEngine On
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
1: Place this code in /Symfony/web/.htaccess:
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [L]
2: Place this code in /public_html/.htaccess:
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
I'm going to go out on a limb and say that your rule is backwards. I think you want your URL to be www.mydomain.com/home/* in the browser... In which case the rule would be reversed. Also, your .htaccess should be in the root and you don't need to include the domain in the rewrite rule because you set a rewrite base.
RewriteRule ^home/(.*)$ Symfony/web/$1 [L,R=301]

Redirection to Desired Url

I have a url like:
http://x.x.x.x/~mmi/
which maps to the public_html folder on my site. I have installed cakephp on my site. The default htaccess file for cakephp looks like below:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I want to be redirected to:
http://x.x.x.x/~mmi/app/webroot/
instead of :
http://x.x.x.x/app/webroot/~mmi/
which is happening now. How should i modify htaccess file to get this desired result?
Following does the trick:
RewriteEngine on
RewriteRule ^~mmi/(.*)$ http://x.x.x.x/~mmi/app/webroot/$1

Resources