htaccess change files extension from .php to .html - php

I have created the redirect rule for seo friendly URL's. I want to remove the .php URL from all pages and requests.
I have tried with the below code but it not working:
Options -Multiviews
Options +FollowSymLinks
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^special-offers.html$ special_offers.php
RewriteRule ^([a-zA-Z0-9-/]+).html$ offer_detail.php?url=$1
RewriteRule ^sear_search.html$ search.php
ErrorDocument 404 /404page.php
I already using this rules in other project and the URL's are working fine, but now it's not workin.

Have it this way:
ErrorDocument 404 /404page.php
Options +FollowSymLinks -Multiviews
RewriteEngine On
RewriteRule ^special-offers.html$ special_offers.php [L,NC]
RewriteRule ^sear_search\.html$ search.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9/-]+)\.html$ offer_detail.php?url=$1 [L,NC,QSA]
Your RewriteBase / directive is routing it to site root directory instead of current directory.

Related

Trying to rewrite the url in WordPress

I have a WordPress url like www.example.com/about and other url which is a normal site in core php www.example.com/about.php
I want to rewrite url structure of WordPress site www.example.com/about to www.example.com/about.php
RewriteEngine On
Options +FollowSymLinks -MultiViews -Indexes
RewriteBase /
RewriteRule ^about.php (.*) about
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^about\.php$ - [L]
RewriteRule ^login/?$ /wp-login.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /about.php [L]
</IfModule>

my website go in 404 page when i put this code in htaccess?

I need this
www.mydomain.com/apple www.mydomain.com/banana
www.mydomain.com/mango to
www.mydomain.com/search.php?q=apple
www.mydomain.com/search.php?q=banana
www.mydomain.com/search.php?q=mango
This is not working
My website go in 404 page
My .htaccess
Options +FollowSymLinks RewriteEngine on
RewriteRule ^(.*) search.php?q=$1
Options +FollowSymLinks
RewriteEngine on
#If the request is not for an existent directory
RewriteCond %{REQUEST_FILENAME} !-d
#And file
RewriteCond %{REQUEST_FILENAME} !-f
#Then rewrite the request
RewriteRule ^(.*)$ /search.php?q=$1

htaccess throwing 500 error

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^read(.+)?$ /read.php?id=$1 [QSA,L]
RewriteRule ^chapter(.+)?$ /readchapter.php?id=$1 [QSA,L]
RewriteRule ^list(.+)?$ /list.php?id=$1 [QSA,L]
</IfModule>
Above is my htaccess file, I trying create a story reading website.
I trying to shorten example link of
http://read.mydomain.com/chapter/three_little_fox/
So when it query
/chapter/three_little_fox
It will actually load readchapter.php?id=three_little_fox
But when I try load the page
http://read.mydomain.com/chapter/three_little_fox/
It throws a Internal 500 error.
Thanks for helping
The current .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^chapter/([^/]*)$ readchapter.php?id=$1 [L]
</IfModule>
But the 404 error exist, my folder is this way
.htaccess
readchapter.php
index.php
Try this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^chapter/(.*)/?$ /readchapter.php?id=$1 [QSA,NC,L]
</IfModule>
RewriteCond (Rewrite Conditions) ensures that if the request is already for a file or directory, RewriteRule will be skipped.
This will work for you:
RewriteEngine On
RewriteRule ^chapter/([^/]*)$ /readchapter.php?id=$1 [L]

url rewrite on godaddy dynamic php pages

I am trying to do a url rewrite for php dynamic pages. The rewrite sends them to the page but I am getting a 404 error. In my php page i use $coinshow =$_REQUEST['coinshow'];
I want to to go from sitename.com/coinShowPage.php?coinshow=XyzShow to sitename.com/XyzShow or I would be happy with sitename.com/coinshows/XyzShow too.
Please note coinShowPage.php is the only page I need redirected.
Here is the .htaccess file
RewriteEngine On<br>
RewriteCond %{THE_REQUEST} ^[A-Za-z]{3,}\s/+coinShowPage\.php\?coinshow=([^\s]+) [NC]
RewriteRule ^ http://www.SiteName.com/%1? [R=301,L]
I already tried the following and it did not work
RewriteEngine On
Options +FollowSymlinks -MultiViews -Indexes
RewriteBase /
RewriteRule ^/([0-9]+)/?$ coinShowPage.php?coinshow=$1 [NC,L]
Any help would be greatly appreciated.
Try this:
Options +FollowSymlinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Za-z]{3,}\s/+coinShowPage\.php\?coinshow=([^\s]+) [NC]
RewriteRule ^ http://www.SiteName.com/%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ coinShowPage.php?coinshow=$1 [QSA,L]

Remove index.php from Codeigniter URL in subfolder with Wordpress in root

I'm having some issues with a Codeigniter app in a subfolder on my server along with a Wordpress install in the document root. If I hide the index.php of the Codeigniter URL with .htaccess
/codeigniter/.htaccess
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|user_guide|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
And get Wordpress to ignore /codeigniter with RewriteCond %{REQUEST_URI} !^/(codeigniter).*$
/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/(codeigniter).*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Then navigate to www.mysite.com/codeigniter/my_controller/my_function, I get a 404 error No input file specified. I found here, that adding a ? after RewriteRule ^(.*)$ index.php solves the Codeiginiter 404 error.
/codeigniter/.htaccess
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
However I'm now getting a Wordpress 404 error, so it seems if I replace index.php with index.php? in /codeigniter/.htaccess, the Wordpress rewrite rule in /.htaccess, RewriteCond %{REQUEST_URI} !^/(codeigniter).*$ gets ignored. Is there a better way to handle this?
Thanks in advance!
The RewriteBase in the codeigniter directory should say /codeigniter/
RewriteBase /codeigniter
Otherwise the rewrite to index.php ends up going to wordpress' router.

Categories