New answers tagged

1

Your use-case is the text-book example of when to completely avoid rewrite rules. To redirect http URLs to https, simply do the following: <VirtualHost *:80> ServerName www.example.com Redirect "/" "https://www.example.com/" </VirtualHost> <VirtualHost *:443> ServerName www.example.com # ... SSL configuration goes here ...


0

Okay, I found the solution: There must be a second rule like this: RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


0

something like: RewriteEngine On RewriteCond %{HTTPS} on RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R,L] Should do the trick in an .htaccess Edit: last part fell off. And indeed if you have no valid ssl the redirect will never get served without an error .. ( letsencrypt has free ssl certs...)


2

I would implement these kind of redirects in the application code itself, creating an array with source and destination URLs, and then testing if the URL contains params in the array, send back a redirect to destination. Using rewrite rules for this is a bit complicated way to implement this.


0

It's easier to do with redirects: Redirect permanent / https://example1.org/ You are using vhosts for both sites, aren't you? Oh, you want to redirect only "/" and nothing else?. Maybe like this? Redirect permanent ^/$ https://example1.org/ Or what are you trying to do?


1

You will need to have an active vhost serving the domain you want to redirect, even if not in use. It will work absolutely fine in the httpd.conf file, Apache is set to read from all *.conf files.


4

It doesn't seem that you want to access anything outside of the /public folder? If so, this seems easy to me, and without any rewrites (I hope there isn't any reason you actually want to use mod_rewrite!) Put index.php in the public folder Set the DocumentRoot to be the public folder Use ErrorDocument to redirect any file not found to index.php If you ...


0

This ruleset works for me. I omitted the check for paths that start /public. RewriteEngine On RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f RewriteRule ^/(.*) /public/$1 [L] RewriteRule . /index.html [L] If /public is not in you document root, you can replacing %{DOCUMENT_ROOT} with the on disk path to the /public directory. The ...


0

Instead of making rewrite rules in .htaccess, it would be much simpler to maintain by doing the mapping inside your PHP script. That array should map the domain name to the username so you'll know how to do your include. If you're afraid of correcting the existing script beyond that, you could even update $_SERVER['SERVER_NAME'] based on it. You could, for ...


0

Try using RewriteBase when you move it to a subfolder: RewriteBase /subfolder/ # Rules


0

Use RewriteRule ^(.*)$ instead of RewriteRule ^ For detailed explanation of rewrite flags i have shared the link below. https://httpd.apache.org/docs/current/rewrite/flags.html


0

Just in case someone needs it, firstly tell apache to treat your php files as text files by dropping the following directive in the the directory you want: AddType text/plain .php Then in all subdirectories under it, turn them back to scripts: AddType application/x-httpd-php .php This should work if the lines are in .htaccess files or <Directory> ...


0

If you have virtual hosts, note that by default Rewrite configurations are not inherited by virtual hosts. In order to "inherit" the directives in the vHost configurations, each vHost configuration needs: RewriteEngine on RewriteOptions Inherit See the Apache documentation for the RewriteOptions directive for more detail. To deny these two files server ...


0

First off I am not understanding what you are trying to redirect but first off the rewrite rules for each web site (vhost) is where the redirects should be added and of those redirects are permanent you should be doing them with Redirect 301 Other than that a quick and nasty solution is to disable all other web sites on apache using a2dissite here's the man ...


18

The recommendation from the Apache project is: In general, you should only use .htaccess files when you don't have access to the main server configuration file. ... a common misconception is that user authentication and mod_rewrite directives must go in .htaccess files. So please both set AllowOverride None and all your other directives in the main ...


1

I have tested with and without .htaccess and could really find no difference in speed or overhead whatsoever. Granted I only run 16 sites and it's a super fast server so in my case tracking milliseconds is almost impossible. On a server running hundreds of sites the overhead may be noticeable so as @Iain said test and see. I personally do everything using ...


1

I don't believe there is a single right answer for your question. Are many variables which can affect htaccess load time: Site folder structure: all .htaccess in each folders are loaded every time the page is open. How long is the htaccess file: 200 lines vs 3500 lines? there is a big difference. .htaccess configuration: rewrite and redirects rules can be ...


3

The expense depends upon how powerful the server is in particular it's storage I/O subsystem and whether there is any caching involved. The way to test it is to configure your system with .htacess and load test it in the same way as you would any web server. Then configure the system without .htaccess and run the same tests. Compare and contrast the ...


0

Figured it out. If you do a separate apache virtualhost and set the server name to be the sub-folder, it will redirect all traffic through that virtual host. ServerName example.com/subfolder DocumentRoot /home/user/public_html/forum


0

Yes. There are tons of ways of doing this. It also depends what modules are enabled and what you can do in your .htaccess file. I prefer using mod_rewrite for rules like this. You can do something like: RewriteEngine On RewriteRule ^(/.+)/[0-9]+-([^/]+)$ $1/$2 [R=permanent] I'm assuming that "category" and "subcategory" are just placeholders and it cant ...


0

Check out the permissions on the files directory. World needs to have the execute permission set to be able to traverse into it. You can set this with chmod o+x files from within the appropriate directory.


0

I deleted files folder and created a new one in my web root, then copied all files to the new folder, now it's working fine.



Top 50 recent answers are included