Site URL alias using mod_rewrite - php

I am developing a website, however I am trying not to have the unattractive url being displaced example instead of : /my_project/master_page.php?page=home and would like to display /my_project/project/welcome and so on, I am trying to achieve this by using mod_rewrite and .htaccess in the site's root directory.
The code is as follows below:
RewriteEngine On
RewriteRule ^project/([^/\.]+)/?$ master_page.php?page=$1 [L]
However I must add I do need some major assistance in achieving this, Thank You.

Related

htaccess rewrite URL does not work with codeigniter code

I am trying to rewrite URLS so that /foo -> index.php.
index.php is powered by codeigniter 3.
bar.php is a stand alone php file.
This is a snipped from my .htaccess:
//Test 1. Bar.php displayed. This works as exptected.
RewriteRule ^/?foo1/?$ /bar.php [QSA,L]
//Test 2. Redirects succesfully to index.php. Works as expected.
RewriteRule ^/?foo2/?$ /index.php [R=301,QSA,L]
//Test 3. Goes to codeigniter 404 page and does NOT display the homepage.
Does not work as expected
RewriteRule ^/?foo3/?$ /index.php [QSA,L]
Why does Test 3 not display as expected? There is something in my codeigniter code that doesn't work when trying to rewrite URLS. Any ideas how to fix this? Is there a workaround?
Full disclosure: the long term aim is to be able to have a URL with structure like this:
example.com/foo1/foo2/foo3/?query1=xxxx&query2=yyyy
rewrite to
example.com/bar/bar1.php?queryA=foo2&queryB=foo3&query1=xxxx&query2=yyyy
Can this be "easily" done within the codeigniter framework (route.php) rather than htaccess? From a development time perspective, just getting it to work via .htaccess would be the preference.
Take a look at https://gist.github.com/keithmorris/3023560
This includes a fairly standard htaccess file that I use on all my projects. You then use the CI routing functionality to define where different bits go.
Bear in mind with CI you can pass additional elements in a url such as example.com/foo1/foo2/foo3/query1/query2.

PHP - make url smaller but with the same functionality

I've got a CMS which I created by myself and I have an external link, which shows the web created by the user.
The link is: http://localhost/CMS/www/users_template/{user_name}
Is there any possibility to change the link and make it:
http://localhost/CMS/{user_name}
but it should still show the web page without any errors?
I think I should edit my .htaccess file, but no idea how to do it. I have never edited the .htaccess file before.
This is a duplicate.
Please view .htaccess: removing part of url path and stay at base
RewriteEngine On
RewriteBase /CMS/
RewriteRule ^www/users_template/(.*)$ $1 [L,R=301,QSA]

Opencart seo url for view all products page

For my opencart site, I'm using a vQmod show_all_product.xml so that the path /index.php?route=product/category&path=0 shows all my products on a category page. It's working perfectly, but ideally what I would like to do is use a SEO friendly URL to achieve this, e.g. /viewall would give the same page.
I would much appreciate if someone could point me in the right direction.
First, make sure mod_rewrite is enabled.
Then, also make sure you can use htaccess (Apache config -> AllowOverride All).
Put this code in your htaccess (assuming it is in root folder, like your index.php file)
RewriteEngine On
RewriteRule ^viewall$ /index.php?route=product/category&path=0 [L]

URL rewrite in apache server

I'm in a situation where my web page have the following types of URL's
http://mysite.com/?type=home
http://mysite.com/?type=aboutus
http://mysite.com/?type=contactus
For the end users I need it to display like the following:
http://mysite.com/home
http://mysite.com/aboutus
http://mysite.com/contactus
This means, the user is not aware that the URL have a request parameter "type" in it.
I'm not sure it is possible or not.
Please help me to get to a solution.
EDIT: I searched lots of websites to learn URL rewrite by using .htaccess, But didnt able to make them working in my server.
Place this in you .htaccess file
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-+/]+)$ ?type=$1
RewriteRule ^([a-zA-Z0-9-+/]+)/$ ?type=$1
Yes it is absolutly possible.
Your have to be sure your hostprovider has enable URL rewriting (I don't really remenber but I'm sur you can find help on Internet to verify that).
You have to create an ".htaccess" file at the root of your site.
Put this content in it :
tell the server to follow symbolic links :
Options +FollowSymlinks
activate the rewrite module :
RewriteEngine on
Rule for rewrite url
RewriteRule ^([a-z]+)$ /index.php?type=$1 [L]
Note this is just a qucik exemple you may want to look "url rewriting tutorial" on Google.

shorter url with php

I've seen it before and I have no clue how to do it or what to look for on google to find it.
Basically I'd like to know how to get these shortened urls to work, what i mean is for example
this: http://website.com/index.php?id=666
turned into this: http://website.com/666
Is there some way to do this through php or do people actually go around making maps for each id?
thanks
Hi there depends what server you are on but if you are using a server with apache that has mod rewrite you can use a htaccess rule.
So an example would be:
first create a .htaccess file then paste in the following content:
RewriteEngine on
RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L]

Categories