.htaccess redirect something to something.html - html

How to derirect
http://www.mysite.com/something
to
http://www.mysite.com/something.html
And
http://www.mysite.com/#something
to
http://www.mysite.com/something.html
Thanks.

For the first you can use,
RewriteEngine On
RewriteRule ^something((/)?)$ something.html [nc]
Or more generally if you want http://mysite.com/X to go to X.html,
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule ^([^.]+)((/)?)$ $1.html [nc]
http://www.mysite.com/#something can't be redirected with a rewrite rule, everything after the # never gets passed to the server. You will need to use JavaScript to redirect those links.

Related

Links (without /index in them) are not pointing to index of that subdirectory

I've looked for about two hours for a way of solving, this to no avail:
Just to make it easier I'm providing links: malumkose.com malumkose.com/hizmetler
In the main page (first link) there is a button link to the page "hizmetler."
When I was linking these pages to one another, I didn't add in the /index or /index.html extensions to the links, and thought it would work on the server as it did on localhost.
The thing is, my site is peppered with these links - they're all over the joint! I would go and manually change these to add the file extension, but that would only cause the link to direct me to "hizmetler/index" instead of just "hizmetler."
I have tried adding the first line here to my .htaccess file, but it still doesn't point links without index in them, to the indexes of these subdirectories.
`DirectoryIndex index.html
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]`
How could I possibly kill these two birds with one stone?
I don't completely understand the structure for the files of your pages, but this should help for your .htaccess file:
Options +FollowSymLinks
RewriteEngine On
DirectoryIndex index.html
RewriteRule ^hizmetler$ ./hizmetler/index.html
RewriteRule ^something$ ./something/index.html
RewriteRule ^something-else$ ./something-else/index.html
Then it will work as follow:
malumkose.com/ > /index.html
malumkose.com/hizmetler > /hizmetler/index.html
malumkose.com/something > /something/index.html
malumkose.com/something-esle > /something-else/index.html
If you want to force SSL/HTTPS, then add (between the enter of the above script):
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

.htaccess: remove .html and redirect slash version

On my site, all pages have .html extension and are directly off the root (i.e., site.com/page.html). I've successfully used the following .htaccess code to make .html not show:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
This gives me a url like site.com/page, but in the event that a user links to or visits the url using a slash (i.e., site.com/page/), I'd like to 301 redirect to the non-slash version.
I'm having trouble integrating this part into the above code. Thanks in advance for any suggestions.
Try to something like this
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

How to redirect website.com/ and website.com/index.php to another page with htaccess

I can redirect website.com/index.php to website.com/home but I can't find a way to redirect website.com to website.com/home
I have tried RewriteRule ^/$ /home [R=301] but it does nothing.
A single rule can handle both redirects:
RewriteRule ^/?(index\.php)?$ /home [NC,L,R=301]
Try this
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$ [NC]
RewriteRule .* http://www.website.com/home [R=301,L]
This rule redirects www.website.com to www.website.com/home
Or add this to your .htaccess
RewriteRule ^/?$ /home [R=301,L]

How to redirect using .htaccess file that redirects from clear domain to www.?

How to redirect:
from mydomain.pl to www.mydomain.pl/start
and
from www.mydomain.pl to www.mydomain.pl/start using .htaccess file?
This should not interfere with any other page. Eg. when somebody types mydomain.pl/contact this should only add www. before the domain.
You can place this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.pl$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.pl$ [NC]
RewriteRule ^$ http://www.mydomain.pl/start [L,R]

htaccess to redirect main domain

I have a htaccess that redirects my main domain "www.main.com" to "www.main.com/DBS2010".
The htaccess works but my url changes to "www.main.com/DBS2010" can I make the url stay as "www.main.com"?
htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?main.com$
RewriteRule ^(/)?$ DBS2010 [L]
You can try this code for that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?main\.com$ [NC]
RewriteRule ^$ DBS2010 [L]
This will not change URL in browser to `/DBS2010'.