SEO Friendly URL (with .htaccess) - .htaccess

I would like to add friendly URL's to my website. But I have one problem. I've never used .htaccess.
My link:
https://example.com/index.php?page=users
I would like to have an URL like this:
https://example.com/page/users
OR
https://example.com/users
Is there anyone who can help me?

Problem is solved with:
.htaccess:
RewriteEngine On
RewriteRule ^([^/\.]+)/?$ index.php?page=$1
So it is very simple.

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

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]

URL Rewriting.htaccess

I want to rewrite a URL through htaccess, but I am not getting the solution to do the specific rewriting. For e.g., I have a URL:
http://www.yourdomain.com/page/about-us.html
Now I want to remove page from above URL, so it should look like;
http://www.yourdomain.com/about-us.html
Can anybody help me with this.
Thanks in advance.
Something like this should work:
RewriteEngine on
RewriteRule ^about-us.html$ /page/about-us.html
If you need it done on any URL put into the site, then something like this:
RewriteEngine on
RewriteRule ^([_\&\'\,\+A-Za-z0-9-]+).html$ /page/$1.html
Assuming you want a 301:
RewriteEngine on
RewriteRule ^page/about-us.html$ /about.html [R=301,L]

SEO Friendly URL Command in .htaccess

I have a dynamic page that looks like the following:
www.sitedomain.com/page.php?id=30&name=about_our_company
I want to make my website links SEO friendly by having something like the following:
www.sitedomain.com/about_our_company.html
Or
www.sitedomain.com/about_our_company
My question is: what regex/code I should have in the .htaccess file?
Thanks
This ofc has a fixed id of 30.
RewriteRule ^about_our_company/?$ /page.php?name=$1&id=30 [NC,L]
since /about_our_company doesn't include the ID, it's impossible to invent the ID correctly.
the way I do it in my own CMS is to have something like this in the .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ /index.php?page=$1 [QSA,L]
then in index.php, use the $_REQUEST['page'] (assuming PHP) variable to find the right page details in the database
You could improve this to be more generic:
RewriteRule ^([^/]+)/([^/]+)?$ /page.php?id=$1&name=$2 [NC,L]
The following URL's would all match:
http://example.com/30/about_our_company
http://example.com/29/contact
http://example.com/10/our_work

Resources