I am using .htaccess file on my localhost and write this code:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^about/?$ about.php [NC,L]
I have checked http.doc file everthing is fine. But its not working fine.
Thanks.
You can put the .htaccess on the www folder and place the content on it:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*)\.php [NC]
RewriteRule ^ /%1.html? [R=302,L]
RewriteRule ^abc/about\.html/?$ /abc/about.php [NC,L]
Related
I am developing a PHP website and I want to redirect php to html and I write the below code in htaccess file. Code is working fine and all the php pages are redirect to html but when I put file name with php in url site is also open with .
RewriteRule ^(.*)\.html$ $1.php [nc]
Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[?\s] [NC]
RewriteRule ^ /%1.html [R=301,L]
RewriteRule ^(.+?)\.html$ /$1.php [L,NC]
I am stuck with .htaccess modification, need a little help.
First off, here is whats inside my htaccess.
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]
For example, I created the file named test.php and uploaded to my server.
I want my server to behave like this.
http://example.com/test/test.html -> http://example.com/test/test.html(as it is)
http://example.com/test/test.php -> http://example.com/test/test.html
but with the .htaccess I have right now,
I still have both .php and .html which may be considered as file duplication by search engine crawler like Google robot (isn't it?).
Any help appreciated.
try this .htaccess code
# Enable Rewrite Engine
RewriteEngine on
#Create friendly URL
RewriteRule ^test/(.*)\.html$ test/$1\.php [L]
OR
RewriteCond %{REQUEST_URI} ^(.*)\.php$
RewriteRule ^(.*) /$1.html [L]
OR
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## .php to .html
# To externally redirect /test/test.php to /test/test.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1.html [R,L,NC]
This is a configuration file of apache '.htaccess' if you still want to configure then change
RewriteEngine on
I hope this work
You may try this in one .htaccess file in root directory:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\.html [NC]
RewriteRule ^([^/]+)/([^.]+)\.php /$1/$2.html [R=301,NC,L]
For silent mapping, replace [R=301,NC,L] with [NC,L]
I have the following .htaccess file
Options +FollowSymLinks
RewriteEngine On
Options -Indexes
RewriteRule ^index/?$ index1.php [NC]
RewriteRule ^index/(.*\.html)/?$ index1.php?load=$1 [NC,L]
RewriteRule ^page/?$ page.php [NC]
RewriteRule ^page/([0-9]+)/([a-z]+)/([{a-z}{0-9}{\-\}]+)/?$ page.php?id=$1&cat=$2&title=$3 [NC,L]
and its work perfectly in my localhost. but not works in server,
the following .htaccess works good in my server
RewriteEngine on
RewriteRule testpage\.html http://www.google.com [R]
did i make any mistake? any help?
I have a mod rewrite working on localhost, but not in godaddy shared host.
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/WebShop/View/public%{REQUEST_URI} -f
RewriteRule ^(.*)$ WebShop/View/public/$1 [L]
RewriteRule ^(.*)$ entryPoint.php [QSA,L]
The problem is with the RewriteCond part. It cannot find the exsiting files in the subfolder. I tried with absolute path, relative path, rewritebase everything, but neither of them worked. Godaddy doesn't grant access to the rewritelog... Any idea how to solve this problem?
Edit:
The htaccess is in a subfolder, and in the document root is a htaccess which splits the request by domain into subfolders:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ([^\.]+\.[^\.]+)$
RewriteRule ^(.*)$ %1/$1 [L,QSA]
And the real problem is, that the %{REQUEST_URI} in the htaccess of the subfolder contains the name of the subfolder too :S
Edit2:
Ok I have a partial solution:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/([^/]+)/(.*)$
RewriteCond %{DOCUMENT_ROOT}/%1/WebShop/View/public/%2 -f
RewriteRule ^(.*)$ entryPoint.php?file=%2 [L]
RewriteRule ^(.*)$ entryPoint.php [QSA,L]
This prints the file name if exists, but it's kind of joke, cause if I change the second rule to
RewriteRule ^(.*)$ x.php [QSA,L]
Then everything goes to the x.php. I'm wondering why mod rewrite never recognize the L flag?
(go drink a beer)
It's maybe because of some sort of strange directory settings, but if you redirect to a subDirectory on a godaddy server, you have to create there an empty .htaccess file with RewriteEngine On, otherwise it won't work.
The preceding code in the edit2 section works well, but not on a godaddy server... Here is the file access version of it:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/([^/]+)/(.*)$
RewriteCond %{DOCUMENT_ROOT}/%1/WebShop/View/public/%2 -f
RewriteRule ^(.*)$ WebShop/View/public/%2 [L]
RewriteRule ^(.*)$ entryPoint.php [QSA,L]
And I placed an empty .htaccess file with RewriteEngine On in the "WebShop/View/public" directory, that fixed the L flag problem.
I'm new htaccess. So i need to rewrite .php to .html in url.
my files located in
http://www.domain.us/sub1/sub2/sub2/index.php
I need to rewrite as
http://www.domain.us/sub1/sub2/sub2/index.html.
I tried something
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} site
RewriteRule ^(.*)\.php$ http://www.domain.us/sub1/sub2/sub3/$1.html [R,L]
But It shows 404 error.
Thanks.
Put this code in your DOCUMENT_ROOT's .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\s/*sub1/sub2/sub2/.*\.php [NC]
RewriteRule ^(.*)\.php$ /$1.html [NC,NE,R=301,L]