I have a website with a structure similar to the following:
/
-- /public/
-- index.php
-- login.php
-- contact.php
Normally on the user is not logged in then he gets redirected to login.php.
So basically when the user types myWebSite.com/ he gets redirected to the index page which redirects him to the login page.
I have added a temp landing page that I want the user redirected to in he does not specify a page in the URL.
Examples:
myWebSite.com/index.php --> index.php
myWebSite.com/login.php --> login.php
However if he does not specify the page then he will be redirected to the new landing page, like so:
myWebSite.com/ --> new landing page
myWebSite.com --> new landing page
With the landing page added the structure is similar to the following:
/
-- /public/
-- index.php
-- login.php
-- contact.php
-- /landing/
-- index.php // new landing page
I known that this can be done using the PHP in the index file. However it will be cleaner to do it in an .htaccss file and also the PHP file can be overwritten by automatic update.
I have tried to several times and failed:
Redirect 301 / /landing/index.php
----------------------------------------------
RedirectMatch 301 /(.*) /landing/index.php$1
Also is there a way to hide landing directory from the URL? even if that means renaming /landing/index.php to landing.php to avoid conflict between it and /index.php
Notes:
I have enabled and tested mod rewrite.
Related
I'm using LAMP hosting on AwardSpace.com.
I have a private folder foobar and when a page </foobar> is requested, it redirects with a 301 to </foobar/> (, allowing pentesters to tell that the folder exists). This is so even after adding a htaccess file:
rewriteengine on
rewriterule foobar$ testpage.php
I believe the server itself is doing the redirection regardless of my hosting content.
How can the redirect be prevented?
(Tried removing traversal access to the folder but it shows 403 and testpage.php doesn't load.)
(For undocumented behavior,) To prevent folders being 301ed‑with‑slash‑appended, you can add a redirect flag to the rewrite rule:
rewriterule foobar$ /testpage.php [r]
With that, no one will know that foobar is actually a folder.
Suppose HTTP redirection is unwanted, r can be appended with =x where x is a value that doesn't cause redirection. This can be 305. This can be 510. This can be 200. In such cases the 3rd argument is ignored (cf):
rewriterule foobar$ yadadadaada [r=200]
Suppose that content is required, content can be added:
errordocument 200 "test page"
, or:
errordocument 200 /testpage.php
I know this is silly question for you but not for me
I am using rdp for manage my account and somehow I got problem in that
Like I have my portfolio in hthocs/portfolio folder, now whenever someone visit it, i need like that
example.com
and whenever someone visit htdocs/example, i need like this
example.com/example
So i only want to redirect homepage folder in my site and other folder behave regularly
I search on internet and I found like that
RedirectMatch ^/$ /portfolio
but using this, its shows correct path like example.com/portfolio
EXAMPLE
Give you example of localhost,
htdocs
|
|--- portfolio (folder)
|--- stackoverflow (folder)
Whenever I visit localhost in browser ( internally it will redirect to htdocs/portfolio ) and when I visit localhost/stackoverflow in browser, It will redirect to htdocs/stackoverflow not in htdocs/portfolio/stackoveflow.
using RedirectMatch ^/$ /portfolio this code, I solved my problem but whenever I visit localhost, in browser its shows real path localhost/portfolio. i don't want to client know it will redirect to this folder
I use # to scroll in website but now when i click on that, it will redirect to original folder
You can use these rules in your site root .htaccess:
RewriteEngine On
# to internally rewrite / to /portfolio
RewriteRule ^$ /portfolio/ [L]
To fix css/js, you can add this just below <head> tag of your page's HTML:
<base href="/" />
I have internal links like: http://example.com/payment/
If to enter this link instead http://example.com/payment I get an error 303.
How to configure .htaccess for redirect?
Add this redirect into your .htaccess file.
This allows you to redirect your entire website to any other domain
Redirect 303 / http://example.com/payment/
Redirecting a URL: Using Redirect in an .htaccess file enables you to redirect users from an old page to a new page without having to
keep the old page. For example, if you use index.html as your index
file and then later rename index.html to home.html, you could set up a
redirect to send users from index.html to home.html.
For example:
Redirect /path/to/old/file/old.html http://www.example.com/new/file/new.html
You can find more detailed examples here.
I'm redirecting a site from an old platform to another. It's got 300-400 pages and all the pages have different names.
It's learn.example.com (old platform) to courses.example.com (new platform)
So I've put in some 301s at the beginning of the .htaccess file of the most important pages, for example:
Redirect 301 /courses-overview/ http://courses.example.com/courses
But at the end I need a catch-all to redirect any other page not previously specified as a 301 like learn.example.com/whatever to courses.example.com to catch any of the other 300-400 pages that don't exist in the .htaccess file now.
Is that possible?
You can Redirectother pages via the following Redirect :
RedirectMatch ^/.*$ http://example.com/
Put this bellow your existing Redirects otherwise Apache will redirect your whole site.
I administer my wife's site, namelymarly.com. Up until last week, the root page of the blog was namelymarly.com/blog/.
Last week I changed it in the WP settings to be namelymarly.com.
WP created the new htaccess file, and I moved the index.php to the root directory (but left the WP folder where it was in the /blog/ directory), as instructed. Everything is working great except for one very important thing:
When you type 'namelymarly.com/blog/' into a browser now, you get a 404 error.
All other URLs, when they include the '/blog/somethinghere', will redirect properly to '/somethinghere.' It's only when there's nothing after '/blog/' that there's a problem.
I tried adding this rule but it still redirects to the 404 page:
RewriteRule ^/blog/$ /index.php
Any suggestions/help?
install "Redirection" and then add a 301 redirect from namelymarly.com/blog/ to namelymarly.com
Did you follow these diections?: Moving WordPress « WordPress Codex
You don't need the redirection plugin. Wordpress handles redirects if you regenerate permaliks. If you have to, use this in .htaccess before the Wordpress rewrite block:
Redirect 301 /blog http://namelymarly.com
But first, be sure you've reset your permalinks in Dashboard/Settings/Permalinks and make sure that copy the changes to .htaccess yourself and that there is only the most recent - the last - rewrite block in the file (WP has a habit of adding more and more rewrite blocks to .htaccess).
And check the URLs of your other URLs in the post/page editor and see if they contain /blog/