Hello Every Body

How can i know that the Site runs on the IIS or Apache Webserver.
And how can i redirect a webpage using 301 Redirect in .htaccess..

in Windows and Linux Server.


I write the Coding in .htaccess but it does not work.

Regards
Ujjwal

Dani AI

Generated

Following up to : start by identifying the server type before editing .htaccess. The simplest check is to fetch response headers (look for a Server: value such as Apache or Microsoft-IIS) or inspect default error pages and common file extensions (.aspx/.asp often indicate IIS; .php/.cgi commonly on Apache). These clues are heuristic only—CDNs or proxies can mask the header—so when in doubt ask the host or check the control panel. Server response header (MDN). (developer.mozilla.org)
You can get headers quickly from the command line with curl -I example.com. (daniel.haxx.se)

If the site is Apache, .htaccess can do 301s but only when the server permits it (AllowOverride) and the right modules are enabled. A simple one-page permanent redirect in the document root:

# in .htaccess
Redirect 301 /oldpage.html https://example.com/newpage.html

To canonicalize or force HTTPS with mod_rewrite:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

See the Apache docs for .htaccess and the Redirect/mod_alias directives for details and context/AllowOverride requirements. Apache .htaccess howto. (httpd.apache.org)

On Windows/IIS you do not use .htaccess. Use IIS Manager > HTTP Redirect for simple redirects, or install the URL Rewrite module and add rules in web.config. Example rule that issues a permanent redirect:

<rewrite>
  <rules>
    <rule name="OldToNew" stopProcessing="true">
      <match url="^oldpage\.html$" />
      <action type="Redirect" url="https://example.com/newpage.html" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

Microsoft documents both <httpRedirect> and the URL Rewrite module. (learn.microsoft.com)

Troubleshooting: verify .htaccess is in the right directory, file is readable by the webserver, AllowOverride/modules are enabled (or put rules in the vhost config), clear browser/CDN caches, and test with curl -I -L to confirm you see a 301. Check server error logs for syntax errors. ’s pointer about read permissions and ’s note about .htaccess being an Apache feature are on the right track—use the above checks to narrow the cause.

Recommended Answers

All 2 Replies

What have you set for redirection and what is "not working"?

AFAIK, the redirection is a single entry (without breaks) like

redirect [[I]status[/I]] oldUrl newUrl

The status is optional and it can be

permanent - (301) resource has moved permanently.
temp - (302). resource has moved temporarily.
seeother - (303) resource has been replaced.
gone - (410) resource has been permanently removed. (When this status is used the new-url argument should not be used.)

Also, check if you have the appropriate read permissions for all the groups.

I believe that .htaccess files are unique to the Apache web server (although I may be mistaken). Apache is the httpd server of choice for Linux ... there is a Windows port as well, but most Windows servers use IIS. I'm not sure how to do redirection on IIS.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.