How do I remove or hide php extension? using .htaccess?
2 Example URL :
http://localhost/folder/test.php?id=1&company=ABC&address=AAAAA
http://localhost/folder/test2.php?username=abcd
Thank You
Add this code in .htaccess for html and php extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L] //for php extension
RewriteRule ^([^\.]+)$ $1.html [NC,L] //for html extension
for query string add these lines
Try this
RewriteRule ^(folder)/(\d+)/([^/.]+)$ test.php?id=$1&company=$2&address=$3 [L]
Try This
RewriteRule ^(folder)/(\d+)/([^/.]+)$ test?id=$1&company=$2&address=$3 [L]
Try this
RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_0-9]+)$ test?id=$1&company=$2&address=$3 [L]
RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_0-9]+)$ test2?username=$1 [L]
i have add every possible solution
Related
I want to remove 2 .php extention from my url and redirect it to non .php extention.
I want to redirect my url
http://localhost/pureherb/products.php/rss_feed.php
to
http://localhost/pureherb/products/rss_feed
my code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^index\.php$ http://localhost/pureherb/ [NC,R]
RewriteRule ^know-your-body-type\.php$ http://localhost/pureherb/know-your-body-type [NC,R]
RewriteRule ^health-care\.php$ http://localhost/pureherb/health-care [NC,R]
RewriteRule ^products\.php$ http://localhost/pureherb/products [NC,R]
</IfModule>
please help me get resolve this issue
It is possible to achieve your requirement by using capture groups in RewriteRule. Here is the example
RewriteRule ^products\.php/rss_feed\.php$ http://localhost/pureherb/products/rss_feed [NC,R]
And here is another example (without hardcoding producs and rss_feed):
RewriteRule ^([^\.]+)\.php/([^\.]+)\.php$ http://localhost/pureherb/$1/$2 [NC,R]
I have a problem whereby google has indexed some pages with the wrong URL.
The URL they are indexing is:
http://www.example.com/user/emp.php
and HTML URL:
http://www.example.com/login.html
I need it to redirect to:
http://www.example.com/user/emp
and HTML URL:
http://www.example.com/login
here is my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
First check, if there exists an appropriate target ending in .html or .php, then rewrite to that URL
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html [L]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [L]
Replace it with this code in your htacess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
And please remove .html and .php from all your links which you are calling for example.
Home
To
Home
Make sure you have the mod_rewrite module is installed, Check the output of phpinfo(); function to confirm. I think the following .htaccess is fine. Place the htaccess in the root of your application.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Read This on how to install mod_rewrite in php
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html
Please help me address my problem, the RewriteRuel 1, 2 and 3 is working. The 4th RewriteRule is not working it sends back 404 error.
1. RewriteRule pahina-(.*)-(.*)-(.*)$ pahina.php?page_id=$1&page_title=$2&user_name=$3 [L]
2. RewriteRule pahina-(.*)-(.*)$ pahina.php?page_id=$1&page_title=$2 [L]
3. RewriteRule pahina-(.*)$ pahina.php?user_name=$1 [L]
4. RewriteRule ^pahina$ pahina.php [L]
The 4th RewriteRule is not working, what I want is to change pahina.php to pahina only without extension... Please help me...
Thanks and best regards...
Here is the code used to remove the .php extension
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
Add this in .htaccess file. This will remove all .php extension.
Specify your file name there
Make sure your patterns are using anchors to avoid matching unwanted text:
Options -MultiViews
RewriteEngine On
RewriteRule ^pahina-([^_]*)-([^_]*)-(.*)$ pahina.php?page_id=$1&page_title=$2&user_name=$3 [L,QSA]
RewriteRule ^pahina-([^_]*)-(.*)$ pahina.php?page_id=$1&page_title=$2 [L,QSA]
RewriteRule ^pahina-(.+)$ pahina.php?user_name=$1 [L,QSA]
RewriteRule ^pahina$ pahina.php [L,QSA]
I am attempting to remove .html and .php extensions from my website's URLs. I have been suggested to use the following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
This indeed works, however it will only work for one extension at a time. So I can either have .html removed, or .php removed from the URL. I need to have both removed simultaneously. Someone suggested I just rename all my .html files to .php, however this will not work for me. Previously, I was able to remove both extensions purely using .htaccess, but am unable to find the solution that I used before.
I also tried this code and it only removes the extension for .html:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
What code do I need to make this work?
Thank you in advance for your assistance!
if php files have more prioritet, than html ones, swap groups of lines
RewriteEngine On
# if exist file.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
# if exist file.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
How can I remove .php extension from php files
htacess file
RewriteEngine On
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
any help is much appriciated, Thanks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ $1.php [NC,L]
If you go to example.com/test/ it will load example.com/test.php
For hat you should define an entry point.
Then you can rewrite your URLs to a parameter of a specified file in that case the index.php.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ index.php?url=$1 [NC,L]
Then you can filter that parameter in your script and show the correct content.
You have an URL something like:
www.example.de/test-test
Then everything is rewritten to your index.php. Other possibility if you rewrite to an existing file. You can do something like this:
RewriteRule ^(.*)/?$ $1.php [NC,L]
Then you fetch everything behind the slash and call an existing PHP file.
Remove .php extension with .htaccess