.htaccess

Is PHP allowed to modify .htaccess file in current folder?

左心房为你撑大大i 提交于 2020-01-01 06:18:08
问题 I have a PHP web app located on shared hosting . My goal is to modify .htaccess file from PHP code when the PHP page is running. I need that .htaccess to insert a couple of mod_rewrite lines into it. The problem is that on Windows+Apache I can dynamically modify .htaccess file but the same code on Linux reports a problem when I try to access this file in any way (copy or fopen): "failed to open stream: Permission denied" I have given .htaccess file 777 permissions - still no result. WHat

htaccess rewrite only if file doesn't exist

泪湿孤枕 提交于 2020-01-01 06:09:13
问题 Using .htaccess mod rewrite, I would like to rewrite a url, check if that file exists, and if not rewrite again to another url using part of the original url which was removed during the 1st re-write. For example, if the original url is this /images/3001/zebra.jpg I would like to check if the file exists /images/cached/zebra.jpg and serve it if it does exist. And if not I would like to rewrite to /image.php?id=3001 Thanks very much, Phil 回答1: In the htaccess file in your document root, add

Redirecting http to https in Google Cloud

自作多情 提交于 2020-01-01 05:42:08
问题 I have setup a load balancer which accepts https connections from users. The compute engines are then connected to load balancer using http connection. I have written the following .htaccess file in the root folder: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] Now, the problem is, the compute engine is always connected via http link (to the load balancer) and not https. Thus, the .htaccess file always consider the connection to be

Symfony2 - redirect /web directory to root

為{幸葍}努か 提交于 2020-01-01 04:36:08
问题 I've got a duplicate content problem with my Symfony2 projet. The following urls gives the same content : www.mywebsite.com/web/page and www.mywebsite.com/page Here is the content of my /.htaccess file : <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ web/$1 [QSA,L] </IfModule> And the content of my /web/.htaccess file : <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php [QSA,L] </IfModule>

Allowing only certain files to view by .htaccess

喜夏-厌秋 提交于 2020-01-01 04:24:07
问题 i have almost 20 pages on server, but i want only a file named abc.php, which users can watch. i want if user forcefully open the other files like //example.com/some.php .htaccess shows 403 error. <Files ~ "^(?!(changepwd|login|register|remind|securitycode|registersuggest)\.php$).*(\.php)$"> AuthName "Reserved Area" AuthType Basic AuthUserFile path_to/.htpasswd AuthGroupFile path_to/.htgroup Order Deny,allow Require group allowed_groups </Files> this is the way i am currently using, but i

Can htaccess read a server environment variable set in Apache?

倾然丶 夕夏残阳落幕 提交于 2020-01-01 04:23:08
问题 When you set a server environment variable in your Apache settings, it's possible to read that variable from PHP using built in functions. But can you read the variable from an htaccess file? What I'm trying to accomplish in my htaccess is something along the lines of: <If var=="stuff"> do things here </if> <if var=="different stuff"> do different things here </if> 回答1: Yes it is. You will probably want to use mod_setenvif functionality, so that module will need to be turned on. Then you

rewriterule in htaccess to match certain file extensions

杀马特。学长 韩版系。学妹 提交于 2020-01-01 04:17:12
问题 How can I look for an instance for certain file extensions, like .(jpg|png|css|js|php), and if there is NOT a match send it to index.php?route=$1. I would like to be able to allow period's for custom usernames. So, rewrite http://example.com/my.name to index.php?route=my.name Current setup: .htaccess: <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^.]+)$ index.php?route=$1 [QSA,L] </IfModule> What

Hide Database Login Information in PHP Code

老子叫甜甜 提交于 2020-01-01 03:13:18
问题 im a total beginner in web programming. Im trying to create a simple website that is reading data from a SQL Database. At first i just wrote my database password and login directly into the php code: <?php $username = "login"; $password = "pw"; mysql_connect("server", $username, $password); ... ?> This obviously isn't a very good idea! So what is a (much) more "secure" way to do this? I read about putting the php code into a seperate file, meaning not into the main php document of the website

Using apache config and htaccess to dynamically set config vars for dev and production

不打扰是莪最后的温柔 提交于 2020-01-01 03:03:05
问题 Short Summary I need to be able to set an environment variable in the Apache site config that defines if the site is dev, beta or production. The htaccess file in the web root will define config variables for the website (database credentials, domain, etc) based on the entry in the Apache configuration ALSO I need to use one of the variables defined in the web roots htaccess in another htaccess located in another directory. Site Configuration Apache config (dev/beta) I would like to set an

Drupal 7 Default .htaccess

…衆ロ難τιáo~ 提交于 2020-01-01 02:34:13
问题 I am after the default .htaccess code for Drupal 7, for some reason the install did not update the .htaccess file at all and it is blank. Any help would be greatly appreciated as I can't find this anywhere. 回答1: Actually, the official Drupal source code is on GitHub: https://github.com/drupal/drupal. The requested .htaccess file can be found here. 来源: https://stackoverflow.com/questions/5864861/drupal-7-default-htaccess