.htaccess rewrite rule mod_rewrite - .htaccess

I have a URL:
http://localhost/sample/custom blog/controllers/sample.php
and I am trying to rewrite it to look like:
http://localhost/sample/custom blog/sample/
I have tried the following but it doesn't seem to work out.
RewriteEngine On
RewriteRule ^custom Blog/([0-9a-zA-Z]+)/(.*) $2 [L]
This to my knowledge should get me at least like this:
http://localhost/sample/custom blog/sample.php
Please help me with this.
And also if you could let me know where I can learn the basics of htaccess, I 'll be delighted.
Thanks.

Place this code in /sample/.htaccess:
RewriteEngine On
RewriteBase /sample/
RewriteRule "^(custom Blog)/([0-9a-zA-Z]+)/$" $1/controllers/$2.php [L,NC]
Make sure there is no .htaccess in custom Blog/ folder.
Reference: Apache mod_rewrite Introduction
Apache mod_rewrite Technical Details

Related

htaccess to remove part of a url, .htaccess

I was wondering how it is possible to remove part of a url with htaccess for example I have a url like this:
http://localhost/item.php?pa=gd34392
now I need to use htaccess to redirect this page or anything like this to a page with this url:
http://localhost/gd34392
I have tried things like this but nothing seems to work and I do not really know my way around htaccess
RewriteEngine on
RewriteRule item.php?pa=$1 /$1 [R=301,L]
You can achieve that using the following rules in your .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /item.php?pa=$1 [L]
Just make sure you clear your cache before testing this.

URL rewrite not working -htaccess

I want to rewrite my site URL structure to a SEO friendly url using htaccess file.
I want to rewrite this URL:
/Site/mysite/tags.php?tag=tag
to
/Site/mysite/tags/tag
This is my script:
Options +FollowSymLinks
RewriteEngine on
RewriteRule /tag/(.*)\.php tags.php?tag=$1
other commands such as DirectoryIndex working properly but my above code not.
i know this question asked before but i can not fix this problem. excuse me please!
thanks.
Your script would rewrite /tag/foo.php to tags.php?tag=foo. What you need is
RewriteRule ^/tag/(.*) /tags.php?tag=$1
Try this code rather :
RewriteEngine on
RewriteRule ^Site/mysite/tag/(.*)$ /Site/mysite/tags.php?tag=$1

Using .htaccess and mod_rewrite

I'm having some mod_rewrite problems with my .htaccess..
RewriteBase /folder
RewriteEngine on
Rewrit­eRule ^(.*)$ basic.p­hp?­url=$1 [L]
Above is what I'm currently using. However, I have no idea what I'm doing to be honest as I'm just cycling through the internet trying to figure this out.
Basically, for my website, if you type in
www.domain.com/folder/xxx/
I want it to basically be www.domain.com/folder/basic.php?url=xxx.
For some reason, all that does is cause a 404 error :/
So can someone please politely point me in the right direction?
Ok, I will explain using your htaccess.
RewriteEngine on
Turn on the Rewrite Module to enable URL rewriting
RewriteBase /folder
Rewrite the Base Directory to directory name folder
RewriteRule ^folder/(.*)$ basic.php?url=$1 [L]
Remap every request make using the folder/***** to basic.php?url=********
Note: RewriteEngine On Should be the first statement on your case
RewriteEngine on
RewriteBase /
RewriteRule ^folder/(.*)$ folder/basic.php?url=$1 [L]
This is more of a problem with regexs than .htaccess files.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
http://www.regular-expressions.info/

mod_rewrite not rewriting url with a subdomain and folder

I'm starting to learn mod_rewrite and experiencing a problem that I can't solve myself.
I have an url: http://abc.domain.com/en/page.php?id=1
which I want to rewrite to http://abc.domain.com/en/1 when a customer visits it.
I've tried something like this
RewriteRule ^([0-9]*)/$ /vacancies.php?id=$1
but it doesn't really work. I believe the problem is with path as my site located on subdomain(abc) and in folder(en)
I would really appreciate pointing me to the right direction.
Use this in your abc.domain.com/en/.htaccess
RewriteEngine On
RewriteBase /en/
RewriteRule ^([0-9]+)/?$ vacancies.php?id=$1 [NC,L,QSA]

How to change the url of my website to a seo friendly one?

I own this website: http://www.finalyearondesk.com .
I want to change the url like :
http://www.finalyearondesk.com/index.php?idname=how-to-recover-ubuntu-after-it-is-crashed
to something like this:
finalyearondesk.com/posts/how-to-recover-ubuntu-after-it-is-crashed
using .htaccess. I don't have any knowledge of .htaccess, and I tried a lot of tutorials available online but all effort goes to vain.
So tell me how to do this.
Create a .htaccess file with this content:
RewriteEngine On
RewriteRule ^posts/([^/]*)$ /index.php?idname=$1 [L]
If it doesn't work, check that the file begins with a dot, that your hoster allows you to use .htaccess files or try to add Options +FollowSymLinks:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^posts/([^/]*)$ /index.php?idname=$1 [L]

Resources