Php url rewrite without htaccess
This is possible solely using language/content negotiation in the Apache configuration (httpd.conf or apache2.conf) along with rewrite rules. Use of an Show In apache2.conf file (or httpd.conf) add the
Then save the file and restart Apache If you specify the
This will not adversely affect content negotiation if you are already serving in multiple languages. For example, replacing example.com/home.php with
Then in apache2.conf:
Your language will still be negotiated but the php extension will not appear in the URL. As other people said, just use links like Else, you could ask your hoster to redirect any URL to /index.php so that you can handle URL rewriting without having Then you can just use a regex match to detect what file to include. Be careful with including the files, use a whitelist so you're sure nobody would be able to load internal files. To disallow the use of htaccess, you need this directive in a
assuming that "/var/www/htdocs" is you document root. To ensure mod_rewrite is loaded, check the httpd.conf file for a Short explanation: The lines:
are conditions to check that the request is not an existing file (
If you want
everything routed to
so that everything gets rewritten except how to remove php extension from url without htaccess : Change the .html to .php. Remove .php extension from URL. Before proceeding further, you need to enable mod_rewrite in Apache web server.
put this piece of code in the root file .htaccess RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L] .htaccess fileRewriteEngine on #remove extension html RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html [NC,L] #remove extension php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php rewrite .php to no extensionRewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] How to Remove File Extension (.php, .html) from URL using .htaccess?Removing .php Extension from URL For example, You required to change URL from http://pakainfo.com/version_1.php to http://pakainfo.com/version_1. Edit .htaccess file and add following settings. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^.]+)$ $1.php [NC,L] RewriteEngine on RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC] RewriteRule ^ /%1 [NC,L,R] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [NC,L] don’t Miss : remove .php from url htaccess Removing .html Extension from URL RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^.]+)$ $1.html [NC,L] Now, If member accessed /version_1 in the browser, it will display the content from /version_1.html. Now, You may required to redirect members which typed complete URL as http://pakainfo.com/version_1.html to the new URL http://pakainfo.com/version_1 RewriteEngine on RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC] RewriteRule ^ /%1 [NC,L,R] RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^ %{REQUEST_URI}.html [NC,L] I hope you get an idea about
. I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage. How rewrite URL in PHP without htaccess?As other people said, just use links like /index. php/nice/looking/url . Else, you could ask your hoster to redirect any URL to /index. php so that you can handle URL rewriting without having /index.. Better use $_SERVER['PATH_INFO'] instead of $_SERVER['REQUEST_URI'] in this case. ... . This workaround looks good.. How rewrite URL in PHP?Here is simple example to begin with.. Folder structure. There are two files that are needed in the root folder, . ... . .htaccess RewriteEngine On RewriteRule ^inc/.*$ index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] ... . index.php. ... . Complete source define( 'INCLUDE_DIR', dirname( __FILE__ ) . '/. How to remove php extension from URL without htaccess?how to remove php extension from url without htaccess : Change the . html to . php. Remove .
|