Redirect all pages to the index page - .htaccess

I have a temporary static HTML page. But there are a bunch of URL's added to an other website. All these URL's go to page a that doesn't exist at the moment. So it needs to be redirected to the index page.
So every page needs to be redirected to https://experienceantwerp.be
Example page that doesn't exist at the moment: https://experienceantwerp.be/nl/aanbod/gidsenwandelingen/geschiedenis/voetgangerstunnel
When you go to that URL, the styles are gone.
My current .htaccess file is
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html/$1 [L]
When I try this, for example: https://experienceantwerp.be/hfhfhf it seems to work. I guess if there is one slash in the URL, it works.
Update: I've found a solution, but it doesn't feel right. When I add the CSS and JS file with there absolute path, it works.

Related

How to redirect HTML index file to subfolder directory?

I have created a subfolder to access my HTML website. But the problem is, it is not running on the subdirectory URL but with the index.html aliases.
e.g. https://example.com/my-html-site/index.html (the website running the whole page).
But I want a simple redirection to run the website under the subdirectory like this below,
https://example.com/my-html-site/ (when I hit this URL then it shows a blank page).
Is there any way to redirect the https://example.com/my-html-site/index.html to https://example.com/my-html-site/ via htaccess file rules?
Thanks in advance,
Based on your shown samples could you please try following. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ $1/index.html [L]

.htaccess Redirect To Another Site's Homepage Only If URL Don't Exist

So this is what I'm trying to accomplish, and I'll do my best to explain...
Through the .htaccess file, I'm attempting to redirect all pages of one site to another site, but ONLY if the URL doesn't exist. If the URL exists, then do nothing. Load that URL. If the URL doesn't exist, redirect to the homepage of another site.
So, going to www.johnny.com/boxing (no files) or even just www.johnny.com (no files) would redirect to www.johnpunches.com, since neither of those URLs work. And that would work for any URL on www.johnny.com that doesn't exist. It would simply redirect to the index page of www.johnpunches.com
However, going to www.johnny.com/members (where there is a working directory) would actually go to that URL and not redirect, because the page exists.
So, again, if the URL exists, then do nothing. Load that URL. If the URL doesn't exist, redirect to the homepage of another site.
RewriteEngine On
# File does not exist
RewriteCond %{REQUEST_FILENAME} !-f
# Directory does not exist
RewriteCond %{REQUEST_FILENAME} !-d
# Redirect to new domain if the above were missing
RewriteRule ^(.+)$ https://www.google.com/$1 [NC,QSA]
Change out google.com to whatever domain you are redirecting to.
Okay, I was able to get some assistance from another thread and put this together:
RewriteEngine on
RewriteCond %{http_host} ^johnny.com [nc]
RewriteRule ^(.*)$ http://www.johnny.com/$1 [r=301,nc,l]
RewriteRule !^folder($|/) http://www.johnkicks.com [L,R=301]
In the example above, the "folder" can be replaced with any directory that works. The second and third line force the www version of the site before the final rule has run so that any URL that DOES work, like johnny.com/folder would redirect to www.johnny.com/folder.
Two questions:
Did I do it correctly? Does the order of my rules work? Should I be doing it any differently?
Would I have to duplicate that fourth line for every working directory?

How to remove the parent from current url path while redirecting using .htaccess

I have been struggling with .htaccess modifications over my site throughout. Here is what i need
I am redirecting user to login page with following url rewritting rule in
.htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^welcome/ index.php [L]
RewriteRule ^log-in/$ log-in.php [L]
The login page when called, the url path that appears in the browser looks like this
http://localhost:90/vrp/log-in/
On login page i have a link added for forget password
<a class="color-aqua" href="forget-password/">click here</a> to reset your password.</p>
Rule for rewritting it is
#Forget Password Rule#
RewriteRule ^forget-password/$ forget-password.php [NC,L]
The Forget password page when called, the url path that appears in the browser looks like this
http://localhost:90/vrp/log-in/forget-password/
I do not want that /log-in to be their on url path. It should be
http://localhost:90/vrp/forget-password/
I did a lot more search and edit stuff around but at the end could not find any way to do it. Is the required thing is possible because this is kind of appending format which may further maximize the url path when user moves in to the portal which may confuse in future.

Rewrite rule to drop .html and to keep the querystring while navigating between pages

I have html pages and I want to remove the .html and keep the query-string in place that when a visitor comes in with a query-string and navigate between pages the query-string remains in place.
So far getting the .html to go is fine, but I cannot get the query-string to stay between pages. I don't particularly want to introduce php into my pages, if its possible with a rewrite rule that will be great.
As follows:
Visitor comes in on homepage www.example.com?ID=123
When visitor clicks on the link www.example.com/page1.html , I want the visitor to go to www.example.com/page1?ID=123
My code currently is as follows:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
Thanks

htaccess seo friendly urls for all subfolders

i have script in index.php in ALL folders
need to make pretty url/seo friendly urls like this: site.com/folder1/something.html
now i have ugly urls like this: site.com/folder1/index.php?category=something
this part index.php?category=something is always the same in all subfolders, i just want to change it to more seo friendly like something.html
once again: find index.php?category=1$ and replace it with 1$.html
do not touch anything else, just this part of url
so when i visit:
site.com/another-subfolder/and-one-more-folder-here/index.php?category=something
need to see this in address bar:
site.com/another-subfolder/and-one-more-folder-here/something.html
i hope you get it?
i tried this with folder1 in htaccess in root
RewriteRule ^folder1/(.*).html$ folder1/index.php?category=$1 [L,R=301]
ok this works, but how can i make this to work for all subfolders accross the site like this:
site.com/folder145/index.php?category=something
site.com/subfolder/index.php?category=something
site.com/another-subfolder/and-one-more-folder-here/index.php?category=something
there will be 1000s of subfolders with different names so manually making RewriteRule for each subfolder won't work
any help is appreciated
First, you need to change all the links that you generate from the index.php?category= form to the category.html form.
Then in the htaccess file in your document root, you add these rules to internally rewrite the category.html form back to the index.php?category= form:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?/)?([^/]+)\.html$ /$1index.php?category=$2 [L]
Then, to point links you don't have any control over (or ones generated using a FORM) externally redirect any direct access to links in the index.php?category= form:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ (/.*?)?/index\.php\?category=([^&\ ]+)
RewriteRule ^(.+?/)?index\.php$ /$1%3.html? [L,R=301]
This should match any and every subdirectory.

Resources