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.
I have to continue on a project that has been developed by someone else. It is a web portal developed using PHP and Wordpress. I am using the code uploaded on localhost.
I had a fundamental question regarding URL rewriting in PHP. I have a link on the front page which says
a href="<?php bloginfo('url'); ?>/search?refer=registered&link=registered
But when I click on it, it gives a 404 error.
How do I set the URL mapping "search" -> "wp-content/themes/mytheme/page-search.php"?
[UPDATE: I found the solution myself. It had to be done through Wordpress by creating templates and setting the URL to point to the corresponding template file.]
wordpress build in url rewriting is in backend after you login /wp-admin/
go settings>permalinks where you can choose the re-write rules and click save button.
wordpress will then auto write a .htaccess file (this file is for url rewriting )
with the rules created in it.
if you find rewriting isn't working (eg, returns a 404 page) then u need to make sure your server has opened the url-rewrite mod for urlrewriting.
I recently changed my wordpress blog's server and URL. Before, it was located at subdomain.website.com and now it is located at website.com/newurl. I copied over the files and database, and updated the site URL and and website URL successfully. Initially, the site seemed to have been functioning properly. Somewhere along the road, the server started feeding back an infinite redirect loop on blog posts only. I can properly view the blog's homepage, but when I try to access specific blog posts it enters into an infinite redirect loop. If I turn of permalinks, and use the raw url i.e. website.com/newurl/?p=232 it serves the page properly.
Any idea why my permalinks no longer work? I already tried turning off plugins, and it still doesn't work. I also tried resetting the htaccess file with no success. Any advice is much appreciated.
Here is my htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Also, I am not sure it is relevant or not, but the wordpress installation is in a subdirectory of a magento installation.
A few things to check...
Have you updated the table wp_options? - There are two fields in there that need to be updated when migrating a website, the option names are siteurl and home.
Also depending on your server settings, you may have to manually update your .htaccess as updating your permalinks doesnt always update your htaccess, a problem Iv run into before.
One last idea, the ‘AllowOverride FileInfo’ directive may be the problem, the .htaccess needs to override the main httpd.conf configuration file and is unable to do so without this directive. (This fixed a problem I had a while ago when the postname permalinks ect were not working but using the actual URL was)
Goto Settings -> Permalink -> Select (Post name) and Save it. No matter it is already selected just do it once again. Goto your site and Refresh page and check urls again. This is a common issue occurs when you migrate in other ways.
Please don't touch your htaccess file.
I have experienced this kind of stuffs in the past and only shows right after you moved wordpress to either another folder, a new domain, or when you change hosting.
To fix it, please correct your Wordpress Address and Site Address... I usually just addd/remove WWW and/or changes HTTPS to HTTP and vice versa
In the end the problem was a plugin titled "WP No Category Base" that was causing the redirect loop. Once I disabled it my website was functioning properly again.
Next time you want to move a WordPress site, you can consider using a WordPress plugin to handle the job for you.
There is several plugins that can do this for you.
Check this one : Golive
GoLive Features:
Automatically Export the Database from Source Server
Transfering the files via FTP automatically
Auto-import Database in Remote/destination server.
Update .Htaccess properly
Update wp-config.php file on destination server with the new credentials.
Replace the URLs in Database (Posts, Pages, Menus…), and keep auto-update serialized objects too.
In my php web site, I need to display my urn in a specific manner
I need to hide the query string parameters and just want to display the value in the URL
i.e.
mydomain.com/city.php?place='usa'&id=2
I need to display
my domain.com/city-2/usa
Is it possible?
Please help me. I am in a serious situation.
Thanks in advance
Yes, it is possible:
RewriteEngine On
RewriteBase /
RewriteRule ^city-(\d+)/(.*) city.php?place=$2&id=$1
You need to put it into the .htaccess placed in the web root of your site. To get it worked you need to have .htaccess parsing enabled and mod_rewrite apache module (assuming you have apache as a web server) enabled as well.
More in official documentation
I have a website that passes some GET variables to different pages in PHP. My issue is that now I have a url with variables i.e. index.php?category=categoryname and that's not very memorable.
Is there any way I can change the URL to something like /categoryname instead without duplicating the page and storing in folders? But also allow users to type in /categoryname and be redirected to the correct page?
.htaccess Apache mod_rewrite, almost every professional dynamic website uses this method (like stackoverflow).
The method is fully explained in this article far better then I could ever explain it in this answer box.
You should look into writing some apache Mod_Rewrite rules in a .htaccess file.
The solution is discussed here:
this is done by the rewrite module of apache and this handles regular
expressions. You have to put a rule
like this in your .htaccess file on
the root of your website:
RewriteRule ^cat/([0-9]+)$
/index.php?category=$1
^ means the start of the url after
www.example.com/ $ means the end of
the page.
www.example.com/cat/123
will be converted by the server to:
www.example.com/index.php?category=123
In PHP you use the normal $_GET['id']
variable. The rewrite module must be
enabled by apache... This is mostly
used to make the url format
independent of the serverside
scripting language so the .php in the
url is not logical. Thats why i
changed it to product/ . The .htaccess
starts with
RewriteEngine On Options
+FollowSymLinks RewriteBase / Here all the rewrite rules.. ...