Domain Url Rewrite - mod-rewrite

What I'm looking to do is rewrite the url so that one of the directories are hidden. For example;
http://www.example.com/home/example.html
to
http://www.example.com/example.html
As I'm new to .htaccess and mod_rewrite, is this something that can be done?

This should work:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/home/.*$
RewriteRule ^(.*)$ /home/$1 [L]

Something like this should work.
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^example.html$ /home/example.html [NC,L]

Related

Masking URL in HTML

I have one HTML page. Assume the URL is
http://localhost/local/local.html
but i want to mask the URL as
http://localhost/local/abc
can we do like this?
Create a .htaccess file in your root of your domain and add the following in that file:
RewriteEngine On
RewriteRule ^local.html$ http://localhost/local/abc/ [R=301,L]
In .htaccess add lines:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?query=$1 [QSA,L]
When you visit https://localhost/local/abc in index.php parse $_GET["query"] how you want.
You can achieve the required action using a htaccess rule ,
Learn about htaccess at :
What is .htaccess file?
.htaccess rule you can implement is follows :
Options +FollowSymlinks
RewriteEngine on
rewriterule ^local/local.html (.*)$ http://localhost/local/abc$1 [r=301,nc]

Rewrite Rule not taking effect

I am trying to rewrite some URLs using my .htaccess file and the following syntax:
RewriteEngine On
RewriteRule ^movie/([0-9]+)/$ movie.php?id=$1
Basically, the URL http://screeningapp.co.uk/movie.php?id=771316320 should be rewritten to http://screeningapp.co.uk/movie/771316320, but that's not happening and I'm not sure why.
Thanks!
RewriteEngine On
RewriteRule ^movie/([0-9]+)/?$ /movie.php?id=$1 [L,nc]
#if you wanna redirect movie.php?id=1 to movie/1/
RewriteCond %{QUERY_STRING} ^id=([0-9]+)($|&)
RewriteRule ^movie.php$ /movie/%1? [R=301,L,NC]

How can I use mod_rewrite to do this

I would like to take a url at my site:
http://mysite.com/jk/drawing
but operationally drop the "jk" dir and have my users see this:
http://mysite.com/drawing
Is this possible? If so can someone give me an example of how it is done?
thanks,
The first thing you need to do is go and change all of your links from looking like this: http://mysite.com/jk/drawing to looking like this: http://mysite.com/drawing. Without doing this, people will still see all the /jk/ URLs everywhere, the only thing you can do about it is to make sure you've changed all your links. Then add these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} mysite.com [NC]
RewriteCond %{REQUEST_URI} !^/jk/
RewriteRule ^(.*)$ /jk/$1 [L]
In order to correct for all the links still pointing to /jk/ that you don't have any control over:
RewriteCond %{HTTP_HOST} mysite.com [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /jk/([^\ ]*)
RewriteRule ^ /%1 [R=301,L]

Creating SEO friendly URLs with htaccess

when I change the link It shows me an error page. maybe there is a problem with my website what do you think?
There is the url in my website: www.mywebsite.com/picture.php?1
and I want to change it to something like this: www.mywebsite.com/picture/1
here is my .htaccess
RewriteEngine on
rewritecond %{http_host} ^website.com [nc]
rewriterule ^(.*)$ http://www.mywebsite.com/$1 [r=301,nc]
RewriteRule ^contact\/?$ contact.php [L]
RewriteRule ^terms\/?$ terms.php [L]
**RewriteRule ^picture/(.*)/$ picture.php?$1 [L]**
Please help,
I have no clue what is the problem.
Try adding
<base href="www.mywebsite.com" />
At the top of your page, this might work.
EDIT:
Try using this rewrite rule
RewriteRule picture/(.*)/$ /picture.php?$1 [L, NC]
assuming that the first part of your htaccess works, replace your last line with the following:
RewriteRule ^picture/(.*)$ /picture.php?$1 [NC]

RewriteRule question

Is there any way i can use RewriteRule to show these links:
/articles_history.php
/articles_geography.php
as
/articles/history.html
/articles/geography.html
I created a .htacesss file on my root directory and would like to know if the above is possible by placing some kind of code in the .htaccess file.
RewriteEngine On
RewriteRule /articles/(.+)\.html /articles_$1.php [L,QSA]
Yes it is.
See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
In addition to RewriteRule, you also need to usually turn the rewrite engine on by the RewriteEngine directive.
Try this in your .htaccess:
RewriteEngine on
RewriteRule ^article/([^/]+)\.html$ articles_$1.php [L]
And for an arbitrary input:
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)\.html$ $1_$2.php [L]

Resources