I created an htaccess i want to rename all extension .php files to .html
i put
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
and it work fine.
Now i want to rename nettoyage-detail-bureaux.php?id=21 to nettoyage-detail-bureaux-21.html
so i add
RewriteRule ^nettoyage-detail-bureaux-([0-9]+)\.html$ nettoyage-detail-bureaux.html?id=$1 [L]
it doesn't work.
Any idea ?
I think you might have a typo at the end where you have .html?id=$1 it should be .php?id=$1
So try this.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^nettoyage-detail-bureaux-([0-9]+)\.html$ nettoyage-detail-bureaux.php?id=$1 [L]
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
Related
Currently my localhost URL is like localhost/apnaujjain/page.php?page_id=1&action=contacts
Now I want to write a rule so that when I go to above url it just rewrite the url like localhost/apnaujjain/contacts.html
See it should convert .php into .html without affect page content.
Until now I've tried
Options +FollowSymLinks -MultiViews
RewriteEngine on
#RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.php?page_id=1$&action=2$
RewriteRule ^(.*)\.php $2.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
But it's not working.
You can use this code in /apnaujjain/.htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /apnaujjain/
# redirect localhost/apnaujjain/page.php?page_id=1&action=contacts to
# localhost/apnaujjain/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2.html? [R=301,L]
RewriteRule ^([^/]+)/([^.]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]
I am having problems with my .htaccess file.
It looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^website\.de [NC]
RewriteRule ^(.*)$ http://www.website.de/folder/$1 [L,R=301]
RewriteRule ^traffic/?$ traffic.php [NC,L]
RewriteRule ^what-if/?$ whatif.php [NC,L]
If I call www.website.de/folder/traffic I get www.website.de/folder/traffic/.
But if I call www.website.de/folder/what-if the trailing / is missing.
How can I add it everywhere?
You have to specify a RewriteBase since your htaccess is in a subfolder.
Also, you have to disable MultiViews option to avoid the problem you have.
Options -MultiViews
RewriteEngine On
RewriteBase /folder/
RewriteCond %{HTTP_HOST} ^website\.de$ [NC]
RewriteRule ^(.*)$ http://www.website.de/folder/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.+)$ $1/ [R=301,L]
RewriteRule ^traffic/$ traffic.php [NC,L]
RewriteRule ^what-if/$ whatif.php [NC,L]
I need to redirect all index.html like this
Original URL
www.example.com/lp/index.html
www.example.com/sytem/index.html
Desired URL
www.example.com/lp
www.example.com/sytem
I used the follwing, it redirects successfully but 404 page
RewriteEngine On
RewriteRule ^index\.html$ [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
You almost got it right, what you did looks like a copy paste error to me. Your first RewriteRule is missing a parameter - there should be a slash before [R=301,L]
Your htaccess should look like this:
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
Reference:
http://dense13.com/blog/2012/10/29/removing-index-html-with-mod_rewrite-in-htaccess/
Place this code in your DOCUMENT_ROOT/.htaccess file:
DirectoryIndex index.html
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteRule ^(.*?)index\.html$ /$1 [L,R=301,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1/index\.html -f [NC]
RewriteRule ^(.+?)/?$ /$1/index.html [L]
Try putting this in your .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1/index\.html [PT,L]
PT and L are rewrite flags, for more details about them check http://httpd.apache.org/docs/2.2/rewrite/flags.html
why not redirect index.(anything) ? like index.php? index.xhtml?
RewriteEngine On
RewriteRule ^index\.(.*)$ / [R=301,L]
RewriteRule ^(.*)/index\.(.*)$ /$1/ [R=301,L]
or to base it from the initial URL request only (to avoid conflicts with other rewrite rules):
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.(.*) [NC]
RewriteRule ^(.*?)index\.(.*)$ /$1 [R=301,L]
I am trying to use my htaccess to allow me to send in a pretty url and have it route to a regular webpage.
So while I am sending in "http://www.foobar.com/dir1/file/id" I would like it to route to "http"//www.foobar.com/dir1/file.php?id=1" As I mentioned, I have been trying to achieve this through my htaccess file but I am just getting 404's all the time. I was hoping one of the gurus here can help me.
This is my htaccess on the dir1 directory:
Options +FollowSymLinks
RewriteEngine on
RewriteEngine on
RewriteRule ^dir1/file/([a-zA-Z0-9]+)$ file.php?id=$1 [L]
Thanks!
Try This its working fine
//First Parameer
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ file.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ file.php?id=$1
//Second Parameter
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ users.php?user=$1&page=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ users.php?user=$1&page=$2
Or try this
Options +FollowSymLinks
RewriteEngine On
# add trailing slash
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
# rewrite gallery/ to gallery.php
RewriteCond %{REQUEST_URI} /$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1.php [L]
# redirect example.com/index.php to example.com/
RewriteCond %{REQUEST_URI} index\.php$
RewriteRule ^(.*)index\.php$ /$1/ [R=301,L]
try this:
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
here you can change (tpl). file into your needs
and further
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
I want to hide all my page names and extension from url,
htt://www.domain.com/innerpage.php
to
http://www.domain.com/
and
http://www.domain.com/subfolder/innerpage.php
to
http://www.domain.com/subfolder/
and
http://www.domain.com/subfolder/subfolder/innerpage.php
to
http://www.domain.com/subfolder/subfolder/
I used like
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ http://www.domain.com/$1/ [R=301,L]
RewriteRule ^(.*)$ http://www.domain.com/subfolder/$1/ [R=301,L]
RewriteRule ^(.*)$ http://www.domain.com/subfolder/subfolder/$1/ [R=301,L]
RewriteRule ^(.*)/$ $1.php [L]
its not work
I think this will work for you
DirectoryIndex innerpage.php index.php index.html index.htm
Put this as first line of your .htaccess. This directive will look for innerpage.php if no page has been specified for a directory. If you want to hide all pages in your site URL's then it's not a good idea IMO.
Give this set of directives a try:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/?$ /innerpage.php
RewriteRule ^([a-z0-9]+)/?$ /$1/innerpage.php
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ /$1/$2/innerpage.php
RewriteRule ^innerpage.php$ / [R]
RewriteRule ^([a-z0-9]+)/innerpage.php$ /$1 [R]
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/innerpage.php$ /$1/$2 [R]
And be surprise what will happened...