apache url rewrite on .htaccess - apache

I need to figure out the code on my .htaccess for the following.
Redirect url http://www.mydomain.com/somekw to http://www.mydomain.com/differentkw
also http://www.mydomain.com/somekw?sort=rating&order=ASC to http://www.mydomain.com/differentkw
I have read up about .htaccess but I have very little skills, hopefully someone can help me out.

This should work:
RewriteEngine on
RewriteRule somekw differentkw [L]
That will change any instance of somekw of differentkw. The GET values will stay there.
Just make sure you have mod_rewrite enabled.

Related

Writing htaccess rewrite rules

I need help in making this htaccess rewrite rule
Suppose I have this url http://test.com/new.php?code=6789767897879&channel=1432
I need to make it http://test.com/live/6789767897879/1432.m3u8 where code and channel number are variable
So far I tried this with no luck but it keeps giving me no page found.
RewriteEngine On
RewriteBase /
RewriteRule ^/live/(.*)/(.*)?$ /new.php?code=$1&channel=$2
I am sorry but I am a beginner. Any effort is appreciated. Thanks again
Could you please try following, written and tested with your shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^live/([^/]*)/([^.]*)\.m3u8/?$ new.php?code=$1&channel=$2 [NC,L]

assistance to with rewrite rule

I want URL to look like www.example.com/chat/91 but really the page is www.example.com/room.php?id=91 I searched online for apache rewrite example but I didn't see any examples in this format to use,
Use this RewriteRule in your .htaccess file:
RewriteEngine On
RewriteRule ^chat/([^/]*)$ /room.php?id=$1 [L]
Make sure you clear your cache before testing this.

Directory rewrite URL in Apache, htaccess

I urgently need help in rewriting php URLs for my site. I have researched and tried everything but it's still not working.
I want to rewrite all the URLs in my htaccess file to rename the directory '_public' to 'art':
www.site.com/_public/work.php
so all url's show:
www.site.com/art/work.php
Can anyone help? would appreciate it very much.
If I understand correctly, you want the user to go to 'www.site.com/art/work.php' and get the page located at 'www.site.com/_public/work.php' displayed.
In .htaccess (in the root directory) do:
RewriteEngine on
RewriteRule ^art/(.+)$ /_public/$1 [L,QSA]
Please add below lines in your htaccess file:
RewriteEngine on
RewriteRule ^art/(.+)$ /_public/$1

Rewriting url using mod-rewrite and apache

I'm trying to add some rewriting on my site, but it seems to not work, I'm using apache and .htaccess.
The code in my .htaccess file is:
RewriteEngine On
RewriteRule ^/?os_framework/?$ /os_framework/index.php?module=home [L,NC,QSA,PT]
This should send http://localhost/os_framework/ to http://localhost/os_framework/index.php?module=home
But it seems not to.
Any help would be appreciated.
In advance, thanks
Edit: Fixed the above, shouldn't have the os_framework/ in the search pattern, however now i cant get this one to work:
RewriteRule ^/(.[^/]*)/?$ /os_framework/index.php?module=$1 [L,NC,QSA,PT]
And what is wrong with
RewriteRule ^(.[^/]*)/?$ /os_framework/index.php?module=$1 [L,NC,QSA,PT]
Why does that throw a error 500? it should work
Try this:
RewriteEngine On
RewriteRule ^os_framework/?$ os_framework/index.php?module=home [L,NC,QSA]

Apache rewrite url

I am trying to rewrite url and it fails. May I know what is wrong? Would someone please enlighten me? I placed the code in .htaccess. I have enabled rewrite_module too.
RewriteEngine On
RewriteRule /place/^([a-zA-Z0-9])$ /placelink.php?lid=$1
For example: domain.com/place/xyz -> domain.com/placelink.php?id=xyz
Update:
I have just found out that my syntax is now correct. But it is not mod_rewrite that is not working. phpinfo shows mod_rewrite module is available.
Update 2
RewriteEngine On
RewriteRule ^/?test\.html$ test.php [L]
Chances are you want this...
RewriteEngine On
RewriteRule ^place/([a-zA-Z0-9-]+)/?$ /placelink.php?lid=$1
This will take requests for..
domain.com/place/the-moon
...and will serve up...
domain.com/placelink.php?lid=the-moon
^ means 'the start of the string. /path/ is a literal. So you're asking for a string which has /path/ in it, after which the string starts. This is logically impossible. See http://regularexpressions.info for more information about regexes.