URL rewriting with PHP

You can essentially do this 2 ways: The .htaccess route with mod_rewrite Add a file called .htaccess in your root folder, and add something like this: RewriteEngine on RewriteRule ^/?Some-text-goes-here/([0-9]+)$ /picture.php?id=$1 This will tell Apache to enable mod_rewrite for this folder, and if it gets asked a URL matching the regular expression it rewrites it … Read more

How to check if mod_rewrite is enabled in php?

If you’re using mod_php, you can use apache_get_modules(). This will return an array of all enabled modules, so to check if mod_rewrite is enabled, you could simply do in_array(‘mod_rewrite’, apache_get_modules()); Unfortunately, you’re most likely trying to do this with CGI, which makes it a little bit more difficult. You can test it using the following, … Read more

Reference: mod_rewrite, URL rewriting and “pretty links” explained

To understand what mod_rewrite does you first need to understand how a web server works. A web server responds to HTTP requests. An HTTP request at its most basic level looks like this: GET /foo/bar.html HTTP/1.1 This is the simple request of a browser to a web server requesting the URL /foo/bar.html from it. It … Read more

Redirect all to index.php using htaccess

Your rewrite rule looks almost ok. First make sure that your .htaccess file is in your document root (the same place as index.php) or it’ll only affect the sub-folder it’s in (and any sub-folders within that – recursively). Next make a slight change to your rule so it looks something like: RewriteEngine on RewriteCond %{REQUEST_FILENAME} … Read more

How to remove .html from URL?

I think some explanation of Jon’s answer would be constructive. The following: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d checks that if the specified file or directory respectively doesn’t exist, then the rewrite rule proceeds: RewriteRule ^(.*)\.html$ /$1 [L,R=301] But what does that mean? It uses regex (regular expressions). Here is a little something I made … Read more

How to debug Apache mod_rewrite

One trick is to turn on the rewrite log. To turn it on, try this line in your Apache HTTP Server main configuration or current virtual host file (not in .htaccess): LogLevel alert rewrite:trace6 Before Apache httpd 2.4 mod_rewrite, such a per-module logging configuration did not exist yet. Instead you could use the following logging … Read more

apache redirect from non www to www

Using the rewrite engine is a pretty heavyweight way to solve this problem. Here is a simpler solution: <VirtualHost *:80> ServerName example.com Redirect permanent / http://www.example.com/ </VirtualHost> <VirtualHost *:80> ServerName www.example.com # real server configuration </VirtualHost> And then you’ll have another <VirtualHost> section with ServerName www.example.com for your real server configuration. Apache automatically preserves anything … Read more

How does RewriteBase work in .htaccess

RewriteBase is only applied to the target of a relative rewrite rule. Using RewriteBase like this… RewriteBase /folder/ RewriteRule a\.html b.html is essentially the same as… RewriteRule a\.html /folder/b.html But when the .htaccess file is inside /folder/ then this also points to the same target: RewriteRule a\.html b.html Although the docs imply always using a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)