skip to Main Content

I want to redirect or rewrite the old URL "more" to "details" in Apache. The file in question is in the user root for Apache. I am using extensionless URLs. I am using .htaccess. How should I do this?

I have tried many regexes with mod_rewrite and tried using mod_alias (is that correct). I have sometimes got a 500 error, or else the redirect doesn’t seem to happen and I simply get a 404.

As every attempt to do this with .htaccess has failed, currently I have various symlinks in place in the file system. So if you try URLs ending in either "/more" or "/more.htm" then all will be well, give the appearance that .htaccess might possibly be responsible.

Here is the current .htaccess (for https://www.skyeshepherdhuts.co.uk):

##
## Adjusted for the website’s production phase, publicly visible
## ==============================================================
##

RewriteEngine On

# disable directory browsing
Options All -Indexes

## ###################
## Forbid access to .htaccess by browser, now produces a 403 Forbidden error; n.b. useful for testing 403)
##
<FilesMatch ".?htaccess$">
    order allow,deny
    deny from all
</FilesMatch>

Header add Content-Security-Policy "default-src 'self';"
Header set Content-Language en-GB

##
## Extensionless URLs technology; if requested no-ext file does not exist,
## and is not a directory and is not already .htm, then rewrite no-ext to .htm
##
##RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !.htm$
RewriteRule ^(.*)$ $1.htm

AddDefaultCharset utf-8
AddCharset utf-8 .css .js .xml .xhtml .html .xhtm .htm .txt
AddLanguage en-GB .htm .xhtml .html .xhtm .txt

AddType text/css                .css
AddType application/javascript  .js
AddType application/xhtml+xml   .xhtml .html .xhtm .htm
AddType application/xml         .xml
AddType application/manifest+json  .webmanifest .manifest .sitemanifest
AddType text/plain      .txt
AddType image/svg+xml   .svg
AddType image/jpeg      .jpg .jpeg
AddType image/png       .png
AddType image/webp      .webp
AddType image/x-icon    .ico
AddType font/ttf        .ttf

ExpiresActive On
ExpiresDefault                      A3600
ExpiresByType image/jpeg            A2592000
ExpiresByType image/png             A2592000
ExpiresByType image/apng            A2592000
ExpiresByType image/webp            A2592000
ExpiresByType image/svg+xml         A2592000
ExpiresByType image/x-icon          A2592000
ExpiresByType font/ttf              A2592000
ExpiresByType application/manifest+json     A2592000
ExpiresByType application/javascript        A2592000
##
## Shorter suggested cache lifetime for file types more likely to change, in case we should do edits
##
ExpiresByType text/css                  A432000
ExpiresByType application/xhtml+xml     A432000
ExpiresByType text/plain                A1200
ExpiresByType application/xml           A1200


####################
# GZIP COMPRESSION #
####################
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml image/svg+xml application/xhtml+xml application/xml application/javascript application/x-javascript application/x-httpd-php font/ttf application/manifest+json
BrowserMatch ^Mozilla/4         gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678]     no-gzip
BrowserMatch bMSIE             !no-gzip !gzip-only-text/html
BrowserMatch bMSI[E]           !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png|webp|ttf)$ no-gzip

### declare the error documents’ names
ErrorDocument 404 "/404"
ErrorDocument 403 "/403"

#########
### Declare the start page
#########
# Uses a level of indirection via "_" in order to avoid having to mention the start page name twice

RewriteRule ^/$     _
RewriteRule ^$      _
RewriteRule ^_$     welcome

— [end of .htaccess]

Note that / in https://www.skyeshepherdhuts.co.uk/ is rewritten to "welcome" (in / ). Any extensionless URL such as "foo" is rewritten to "foo.htm". So https://www.skyeshepherdhuts.co.uk/welcome is rewritten to https://www.skyeshepherdhuts.co.uk/welcome.htm

2

Answers


  1. there are couple of ways to do this

    1. Use navigo.js

    2. using htaccess
      RewriteEngine On
      RewriteCond %{REQUEST_URI} !^/client/$
      RewriteRule ^index.html$ – [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . index.html [L]

    further explanation from your end needed to provide solutions

    Login or Signup to reply.
  2. I understand the question such that you want to redirect or rewrite requests to /more to /details. Presumable that URL should the get treated the same as any other URL, so for example also get appended with a .htm file name extension (did not know those were still in use …).

    1. external redirection:

      RewriteRule ^/?more$ /details [R=301,L]

    That rule should get applied prior to any other rewrite rule. So it should be place above other rules in the configuration file.

    It is a good idea to start out using a R=302 temporary redirection. And to only change that to a R=301 permanent redirection once everything works as desired. That prevents nasty client side caching issues while testing. Still you should always test using a fresh anonymous browser window.

    1. internal rewrite:

      RewriteRule ^/?more$ /details [L]

    That rule also should get applied before any other existing rewrite rule.

    Both rules can be implemented in the central http server’s host configuration. Or, if you do not have access to that, you can also use a distributed configuration file, though that comes with a number of disadvantages.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search