Hi all,
I want to create SEO friendly URL's using pure PHP without using htaccess. How i can do it?
For example: http://www.example.com/profile.html, while i give this URL, it should show the content of http://www.example.com/profile.php.
Any idea about this issue? please share with me. Thanks in advance.
URL rewrite using PHP without using .htaccess
Moderator: General Moderators
- mrvijayakumar
- Forum Commoner
- Posts: 58
- Joined: Tue Aug 18, 2009 12:39 am
- Location: Chennai city, India
- Contact:
Re: URL rewrite using PHP without using .htaccess
Not definate, but I'm pretty sure you can add the .htaccess handler to the php ini file (AddHandler x-httpd-php .htm .html)
Do .html have any seo gains over .php anyway? I can understand http://www.example.com/profile/, however you really would need htaccess for that to work best.
Do .html have any seo gains over .php anyway? I can understand http://www.example.com/profile/, however you really would need htaccess for that to work best.
- volomike
- Forum Regular
- Posts: 633
- Joined: Wed Jan 16, 2008 9:04 am
- Location: Myrtle Beach, South Carolina, USA
Re: URL rewrite using PHP without using .htaccess
Not possible if this is Apache. You'd either have to add the .htaccess file, or edit the default settings of the Apache webserver. The idea being that you'd add this in:
<FilesMatch "\.html">
AddType application/x-httpd-php .php .html
</FilesMatch>
Or you'd have to hook the 404 logic such that it goes to the .php file, but even that is not recommended and creates a lot of problems.
Another approach is to turn on MultiViews on the Apache web server and then instead of ending with .html, just leave the file extension off entirely, such as:
http://example.com/profile
The MultiView feature I think will then fire profile.php for you if I'm not mistaken.
However, some experienced Linux sysops consider that a security hole and dislike MultiViews.
No matter what, if this is Apache, the way to do this the right way is to use the .htaccess feature. The way I do it with .htaccess is like so:
SetEnv URL_PREFIX /mysite
# or "SetEnv URL_PREFIX /" if path to index.php are run off the domain name and not a subfolder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . %{ENV:URL_PREFIX}index.php [QSA]
<FilesMatch "\.html">
AddType application/x-httpd-php .php .html
</FilesMatch>
Or you'd have to hook the 404 logic such that it goes to the .php file, but even that is not recommended and creates a lot of problems.
Another approach is to turn on MultiViews on the Apache web server and then instead of ending with .html, just leave the file extension off entirely, such as:
http://example.com/profile
The MultiView feature I think will then fire profile.php for you if I'm not mistaken.
However, some experienced Linux sysops consider that a security hole and dislike MultiViews.
No matter what, if this is Apache, the way to do this the right way is to use the .htaccess feature. The way I do it with .htaccess is like so:
SetEnv URL_PREFIX /mysite
# or "SetEnv URL_PREFIX /" if path to index.php are run off the domain name and not a subfolder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . %{ENV:URL_PREFIX}index.php [QSA]
Re: URL rewrite using PHP without using .htaccess
Ah, so I was wrong lol, but close!