I am using the code below in .htaccess to remove .html from the end of file names and folder name, but the problem I'm facing is currently the website is only able to view with index or index.html.
The mainpage will shown only when I type
www.domain.it/index or www.domain.it/index.html
**and will return to error 404 when i type www.domain.it
What should i do if I want the mainpage to be www.domain.it
Options +MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+pages/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^pages/)^(.*)$ /pages/$1 [L,NC]
Related
Homepage TLD resolves fine.
When clicking on subpage link e.g. "mortgages/" the subpage does not display, instead the homepage is displayed, although the pretty URL does display correctly as www.mydomain.co.uk/mortgages/
The subpage will only display if I enter the actual page "mortgages.php" into the menu structure.
So it seems that the subpages are not parsing correctly for some reason.
Could this be an HTACCESS issue?
Have tried various changes to HTACCESS
Current HTACCESS code
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
IndexIgnore *
When clicking on subpage link e.g. "mortgages/" the subpage does not display, instead the homepage is displayed, although the pretty URL does display correctly as www.mydomain.co.uk/mortgages/
I think this is what you want
remove php file extension-e.g. https://example.com/file.php will become https://example.com/file
alternative 1
Options +MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
alternative 2
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
Here is my url:
website.com/index.php?folder=cars&type=ford
and would like it to be website.com/cars/ford and all pages point to index.php that I will grab the params from the url.
I can't seem to get it, here is my .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /index.php?folder=$1&app=$2 [L]
This is one example I got from a clean url generator but its not working. Any ideas?
You can insert this rule just below RewriteEngine On to redirect old URL to pretty URL:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php\?folder=([^\s&]+)&type=([^\s&]+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?folder=$1&app=$2 [L,QSA]
I have this code in my .htaccess file
RewriteEngine on
ErrorDocument 404 http://example.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
RedirectMatch ^/(.*?)/$ /$1
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
Now I have http://example.com/services.html which redirects to http://example.com/services
It's working perfectly until I created a subfolder which named services.
I tried creating index.html in the said subfolder but I got no luck.
How can I have http://example.com/services and http://example.com/services/service1 both working?
Thanks in advance.
After some help from another question i managed to figure out about .htaccess on my website for Friendly SEO links.
My public_html folder contains those files
index.php
.htaccess
buisnessdetails.php
eventDetails.php
My htaccess so far is this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
</IfModule>
So when someone clicks an href which has http://sourtouki.gr/123/abc
the htaccess file goes to the
eventDetails.php file.
But now i want it to change like this
i've edited my public_html folder like this
index.php
events(folder)
2.1 eventDetails.php
buisness(folder)
3.1 buisnessdetails.php
So with these changes i want to do the following thing
Changed the href link to
http://sourtouki.gr/events/123/abc
What changes i must do to the .htaccess file so it can understand that if someone pushes the above link, to go to the eventDetails.php which is inside events folder??
And is it going to be editable so i can add also buisness folder inside that rewrite rule?
You can use something like :
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /events/eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /events/%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]+)/([^/]+)/?$ /events/eventDetails.php?id=$1&name=$2 [L]
I have the following directory structure:
public_html/sites/site_a/
public_html/sites/site_b/
I am trying to write a .htaccess for site_a that rewrites urls. I have the following sitting in the root directory of site_a:
Options +FollowSymLinks
RewriteEngine On
RewriteRule \?page=([a-z]*) $1 [L,QSA]
Basically I would like to have my urls:
http://hostname/sites/site_a/?page=products
Show as:
http://hostname/sites/site_a/products
However this doesn't seem to work. The page shows with the full url.
Try:
RewriteEngine On
RewriteBase /sites/site_a/
RewriteCond %{THE_REQUEST} \ /+sites/site_a/\?page=([^&\ ]+)
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ ?page=$1 [L,QSA]
in the htaccess file in your site_a directory.