Mod_rewrite rewrite URL doesn't do anything - apache

For some reason Apache doesn't rewrite my URL's and I can't figure out what's wrong.
I can confirm that mod_rewrite works because this works:
RewriteEngine on
RewriteRule ^oranges.html$ apples.html
And it shows the apples.html page.
I am trying to use this but it doesn't do anything!
Options -Multiviews +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)[/]*$ index.php?page=$1
To look like this: http://example.com/search/
What could be wrong here? :o

Related

Why is mod_rewrite adding var/www/html to the resulting url

I am trying to make my service backward compatible, since I have moved the service to a new path internaly, I still want the users to access it with the old url as not all of them have knowledge of this change.
I can accomplish what I want if I add [R] flag at the end of my rewrite rule but it redirects the url on the client side, which I don't want.
My rewrite code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/old-path(.*)$ /new-path/$ [L]
</IfModule>
Although this rule results in the following url:
/var/www/html/new-path
Sample request looks something like:
https://host-name/old-path/param1/param2/param3/param4
and rewrite rule should just replace old-path with the new-path.
Can anyone give me some clues about what am I doing wrong? and how can I fix it?
Thanks in advance!
If your are aiming for 'hiding' the rewrite, try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/old-path/(.*)$ /new-path/$1 [P,L]
</IfModule>
And if you REALLY want to extract the hostname:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} (.*)
RewriteRule ^/old-path/(.*)$ http://%1/new-path/$1 [P,L]
</IfModule>
Since %1 references the first bracket of RewriteCond-line...
If you want customers to be rewritten to the new URI and see that:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/old-path/(.*)$ https://host-name/new-path/$1 [R=301,L]
</IfModule>
or in short, and without even using a rewrite:
RedirectMatch ^/old-path/(.*)$ /new-path/$1
To avoid 'https://host-name/' change your DocumentRoot to the parent-directory of 'old-path' and especially 'new-path'.

.htaccess is not rewriting my url

i'm quite new to .htaccess file and I nees a bit of help..
I have a Greek site and I want to have urls like επικοινωνία.html. However, I haven't managed to translate successfully using htaccess file.
My code, for example, is:
Options +FollowSymlinks
RewriteEngine On
RewriteRule επικοινωνία.html contact.html
However, the url showing in the browser is not changing at all.
What am I missing?
Try this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^επικοινωνία\.html$ /contact.html [L,B,R]

htaccess mod_rewrite Shorten to a SEO friendly URL

I have this address
http://www.nfrases.com/tag.php?id_tag=10&id_frase=508
that I would like to make it a lot shorter and more SEO friendly to something like (I don't know ... open to suggestions) http://www.nfrases.com/tag/10/508 or http://www.tag10name.nfrases.com/508
I need help with how to code this, because a simple thing as trying to make the address always http://www.nfrases.com case the user goes to http://nfrases.com or www.nfrases.com I tried and failed :(
Used this code by the way:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.nfrases.com$
RewriteRule ^(.*)$ http://www.nfrases.com/$1 [R=301]
http://www.nfrases.com/tag.php?id_tag=10&id_frase=508
becomes
http://www.nfrases.com/10/508
with this in your .htaccess
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^([0-9]*)/(.*)/?$ /tag.php?id_tag=$1&id_frase=$2 [L,QSA]
Untested. Let me know if it works for you.

Apache mod rewrite .htaccess

I can get basic tests to work with mod rewrite ie:
RewriteEngine on
RewriteRule ^index.php$ test.php
But what I'm really trying to accomplish is changing my dynamic url ie:
detail.php?id=1
to something like
detail-id-18.htm
Now this is what I have in place (that I thought would have worked) but of course nothing is happening:
RewriteEngine on
RewriteRule detail-id-(.*)\.htm$ detail.php?id=$1
Try this
RewriteEngine On
RewriteBase /
RewriteRule ^detail-id-([0-9]+)\.htm$ detail.php?id=$1

apache rewrite htaccess

I've been trying things on my server but I can't figure out what's going wrong.
As of now, this is the .htaccess I have:
Options +FollowSymlinks
RewriteEngine on
RewriteRule (.*) $1 [NC, L]
Instead of rewriting to 'match' it rewrites to 'match'.php
Any idea why?
The MultiViews option can cause such a behavior. Try to disable it.