Response
stringlengths
8
2k
Instruction
stringlengths
18
2k
Prompt
stringlengths
14
160
Deploying Laravel app in cPanel is quite simple(if you are deploying on add-on domain).In cPanel, go on add-on domains and then create a new add-on domain.By default cPanel generates document root for you in this manner:public_html/mydomain.comChange it to:public_html/mydomain.com/MyLaravelApp/publicNow upload your Laravel project underpublic_html/mydomain.comdirectory.It should look like this.If you have already an add-on domain. Go to Modify add-on domain (just below Create an Addon Domain)Click edit icon in document root column and change your domain's document root.
I am trying to deploy my laravel 5.1 application on shared hosting cpanel. But I am getting 404 error.404Not FoundThe resource requested could not be found on this server!To upload the project, I make a clone of project directory and uploaded it on cpanel via their FileManger. Then move the Public folder items into Public_Html.My .htaccess file content is shown below:<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteBase / # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>I also changed the following lines in index.php:require __DIR__.'/../bootstrap/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';torequire __DIR__.'/../objecsys/bootstrap/autoload.php'; $app = require_once __DIR__.'/../objecsys/bootstrap/app.php';What could be wrong with this deployment approach?
Laravel Deployment on Shared Hosting - 404 Error
For advanced application follow these steps:1) Add the followinghtaccesstofrontend/webRewriteEngine on # If a directory or a file exists, use the request directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward the request to index.php RewriteRule . index.php2) Add the followinghtaccesstoroot folderwhere application is installed# prevent directory listings Options -Indexes IndexIgnore */* # follow symbolic links Options FollowSymlinks RewriteEngine on RewriteRule ^admin(/.+)?$ backend/web/$1 [L,PT] RewriteRule ^(.+)?$ frontend/web/$13) Edit yourfrontend/config/main.phpfile with the following at the topuse \yii\web\Request; $baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());4) Add therequest componentto the components array in the same file i.efrontend/config/main.php'components' => [ 'request' => [ 'baseUrl' => $baseUrl, ], ],That's it.Now you can access the frontend without web/index.phpFor you second question you need to write the rule for it in your URL manager component.Something like this:'urlManager' => [ 'baseUrl' => $baseUrl, 'class' => 'yii\web\UrlManager', // Disable index.php 'showScriptName' => false, // Disable r= routes 'enablePrettyUrl' => true, 'rules' => array( 'transaction/getrequestdetail/<id>' => 'transaction/getrequestdetail', ), ],
first question: i already removeindex.php, but i want remove/webalso. this is my.htaccessRewriteEngine on # If a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward it to index.php RewriteRule . index.phpand this isconfig/web.php'urlManager' => [ 'class' => 'yii\web\UrlManager', // Disable index.php 'showScriptName' => false, // Disable r= routes 'enablePrettyUrl' => true, 'rules' => array( '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ), ],it's working fine, but it's still using/web. is it possible remove/web?second question:i can't set route with parameter with that clean url, my routeUrl::toRoute(['transaction/getrequestdetail/', 'id' => 1 ]);how the route should be ? and how with 2 parameter route ?
how to remove url (/web/index.php) yii 2 and set route with parameter with clean url?
Ok you first need to enable mod_rewritesudo a2enmod rewrite sudo service apache2 restartthen open apache conf filesudo gedit /etc/apache2/apache2.confuncomment this line if it is commentedAccessFileName .htaccessyou need to change AllowOverride toAll- note my root is var/www/html yours might be just var/www<Directory /var/www/html/> Options Indexes FollowSymLinks AllowOverride All Require all grantedRestart apache and that should do the tricksudo service apache2 restart
I have integrated my codeigniter project with Ubuntu 14.04. It was giving me url not found errors after the default controller, which is login controller.Please find following .htaccess file<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /myapp/ #Removes access to the system folder by users. #Additionally this will allow you to create a System.php controller, #previously this would not have been possible. #'system' can be replaced if you have renamed your system folder. RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L] #When your application folder isn't in the system folder #This snippet prevents user access to the application folder #Submitted by: Fabdrol #Rename 'application' to your applications folder name. RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/$1 [L] #Checks to see if the user is attempting to access a valid file, #such as an image or css document, if this isn't true it sends the #request to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule> <IfModule !mod_rewrite.c> # If we don't have mod_rewrite installed, all 404's # can be sent to index.php, and everything works as normal. # Submitted by: ElliotHaughin ErrorDocument 404 /index.php </IfModule>
I get URL not found issue error using codeigniter in Ubuntu 14.04
Try replacing your .htaccess file with the following# Turn rewriting on Options +FollowSymLinks RewriteEngine On RewriteBase / #if the request does not end with test.html or is not a .png RewriteCond %{REQUEST_URI} !(test\.html|\.png)$ [NC] # Rewrite it to test.html RewriteRule .* /test.html [L]
I'm trying to use htaccess redirect to a file, but can't get the image to display.I want to redirect ANY request to mydomain.com or www.mydomain.com to www.mydomain.com/test.htmlThis is the content of my htaccess file:# Turn rewriting on Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_URI} !=/test.html RewriteCond %{REQUEST_URI} !=*\.png$ [NC] RewriteRule .* /test.htmlI have this line of code in my test.html file:<img src="image.png" alt="My Image">But the image doesn't display at all, I just get a broken image. I also tried using absolute path for image, same thing.
htaccess redirect but exclude images
You should check the filepermissions.I once got that same error, I changed the filepermissions form666to644
I have a site with news messages.And in my.htaccesfile I have this line of code.RewriteRule ^event/([0-9]+)/?$ events.php?id=$1If I go to mysite.com/index/event/1 I get an500 internal server errorThe weird thing is that if I change the.htaccestoRewriteRule ^event/([0-9]+)/?$ nieuws_read.php?id=$1I don't get that error and the page works correctly.How is it possible that it doesn't work with all files.I got this error[Tue May 27 17:46:41 2014] [error] [client ipadress] SoftException in Application.cpp:249: File "/../../../../public_html/new/events.php" is writeable by group, referer: http://new.mysite.eu/index/events [Tue May 27 17:46:41 2014] [error] [client ipadress] Premature end of script headers: events.php, referer: http://new.mysite.eu/index/events [Tue May 27 17:46:41 2014] [error] [client ipadress] File does not exist: /../../../../public_html/new/500.shtml, referer: http://new.mysite.eu/index/eventsI hope I gave you enough info. Thx
SoftException in Application.cpp:249: can't acces file
Place the following configuration into your.htaccesslocated in the root of your website:RewriteEngine On RewriteCond %{REQUEST_URI} !^/splash.html$ RewriteCond %{REQUEST_URI} !^/images/usedimage.png$ RewriteCond %{REQUEST_URI} !^/images/anotherusedimage.png$ RewriteRule .* /splash.html [R=301,L]
I am taking a site permanently offline, but I'm displaying a splash page on it for a week or two before it goes down. How can I edit my .htaccess file to display that splash page? It needs to allow the page itself (root directory) as well as two images in the /images directory.
Using .htaccess to redirect all pages except three
I've found answer to my question:Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTPS} !on RewriteCond %{REQUEST_URI} ^(/(client/|doctor/)) RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^(/(client/|doctor/)) RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
When I try to create rules for redirect from HTTP pages to HTTPS pages (only for specific pages) with .htaccess, I've received loop redirect. Where am I wrong?Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTPS} !on RewriteCond %{REQUEST_URI} ^(/doctor) [NC, OR] RewriteCond %{REQUEST_URI} ^(/client) RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L] RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^(/doctor) [NC, OR] RewriteCond %{REQUEST_URI} !^(/client) RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]
Permanent redirect from http to https page
Even thoughmod-rewriteis enabled, by default it is not enabled for.htaccessfiles.Hold Your BreathOpen xampp control panelStop ApacheClick theConfigbutton on the Apache row, and selecthttpd.confIn that file, search for something likexampp/htdocs">A bit lower, you may see a line like this:# AllowOverride All. Remove the#, which is a commentAlternately, search forAllowOverride All, make sure it is in the right section, and remove the comment#Save the fileRestart Apache, say a prayer, cross your fingers and hold your breath
I'm setting my.htaccessfile right now to usefriendly urls(manually). But, when i go to the url the server shows meError 404.RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f Rewriterule ^register$ register.phpI'm really sure thatmod_rewriteis enabled because i see it when usephpinfo().
.htaccess doesn't work on xampp (windows 7)
I made this way:Created the .htaccess in the root folder of the project with the content:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php|css|js|images|robots\.txt) RewriteRule ^(.*)$ index.php?$1 [L]Then, in the config.php i modified this line.From:$config['url_suffix'] = 'index.php';To:$config['url_suffix'] = '';
I have a little project that i developed for a client in codeigniter 2.1.4 and now, he insists to migrate to codeigniter 3 DEV version. I know that's not a good ideea but... My problem is that i can't remove the index.php from the url.This is my .htaccess file :Options +FollowSymLinks RewriteEngine on # Send request via index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L]I have removed the index.php from the config.php fileNo luckI reinstalled the LAMP server (i'm on Ubuntu 12.04'), reconfiguredI have other projects on my local server developed on Codeigniter 2.1.4 and Laravel 4 and they work just fine but this one it's killing me.Thank you!
Codeigniter 3 Remove index.php Problems
also in .htaccess you can allow from your ip/subnet, like this:Order Deny,Allow Deny from all Allow from 192.168.1.1/24of course it should match your LAN
Hi i've got another question, i'm writing a simple website in PHP and i have problem with visibility of my website in local network to make it visible to remote addresses i used$_SERVER['REMOTE_ADDRESS'], but i want to make it visible in my LAN.How can i do this ??
PHP - how to make page visible only in local network
Sure:RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]The second condition checks if theHTTPSenvironment variable (eitheronoroff) is set toonand captures the appendedsthat is then available with%1. If it doesn’t match,%1is just an empty string.
There are a lot of code examples for using .htaccess to add www to a url but they are usually confined to using http. does anybody have an example of how to get it to work in both cases?
use htaccess to add www with https support
Assuming this is your literal code:require_once('/wp-includes/class-phpass.php');No wonder the file can't be found, asrequireoperates on the filesystem level, so you probably need something like/var/www/mysite/wp-includes/class-phpass.phpinstead.You should be able to get it work like this:require_once $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/class-phpass.php';This inserts the current root path of the web site before the subpath.$_SERVER['DOCUMENT_ROOT']is by default the only semblance PHP has of a 'root path' unless you teach it better.
I have a web site made by wordpress and I made some php files that i want to execute and for some reason I need to require_once(/wp-includes/class-phpass.php) but I got Failed opening required Error, there is a htaccess file in root folder and it doesn't exist in wp-includes folder the htaccess contain this:# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPressso how to solve this problem?! , ThanksEditmy wordpress is not installed in the root folder it's like root/live
how to allow require_once() to php file in wordpress
Better to have separate clean rules. Put this code in yourDOCUMENT_ROOT/.htaccessfile:RewriteEngine On RewriteRule ^index\.php$ - [L] RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA] RewriteRule ^([a-z]{2})/([^/]+)/?$ /index.php?page=$2&lang=$1 [L,QSA] RewriteRule ^([a-z]{2})/([^/]+)/([0-9]+)/?$ /index.php?page=$2&lang=$1&article=$3 [L,QSA] RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&article=$2 [L,QSA]
I know this problem is over asked, but couldnt find anything fitting with my problem.I'm currently creating a website, and my url are like :www.foo.com/ or www.foo.com/index.php. They can take 1, 2 ,or three different parameters likewww.foo.com/index.php?page=Home&lang=en&article=1What i'd like is an url likewww.foo.com/Home/ or www.foo.com/en/Home or www.foo.com/Article/1 or www.foo.com/en/Article/1The page parameter is required, other two are not.. I cant have anything working for me... Any help would be greately appreciatedThanks a lot !
htaccess multiple parameters rewrite rule
do this before you call geoip:$_SERVER['REMOTE_ADDR'] = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
CloudFlare provides the user's country from the originating IP but I need location on a city level so I've added MaxMind's GeoCityLite using the mod_geoip Apache script.The problem is now to get the IP in a php variable, I'm using something like$country = apache_note("GEOIP_COUNTRY_CODE");This is great but the IP mod_geoip is using is the CloudFlare DNS, not the end user. CloudFlare offers the server variable HTTP_CF_CONNECTING_IP to use the end-user IP but how do I use THAT variable/IP in the mod_geoip?Can this be done with a few lines in htaccess?Edit: I have a workaround using the php API for geoip which is easy but the benchmarks using the apache lookup of the php api is much much better so I'd rather find this solution.
How can I get the user's IP while using both CloudFlare and MaxMind's GeoIP with mod_geoip?
Actually I solved my problem adding a slash to the beginning of every Rewrite Rule, like:RewriteRule ^(.+\.php)/?$ /index.php?url=$1 [QSA]instead ofRewriteRule ^(.+\.php)/?$ index.php?url=$1 [QSA]Thanks!
I uploaded the current .htaccess file to a 1and1 server (actually 1und1.de, but I guess it's the same) and I'm geting a 500 Internal Server Error.Options -MultiViews RewriteEngine On RewriteBase /lammkontor RewriteRule ^categories/([^/\.]+)/?$ index.php?url=category.php&cat_url=$1 [L] RewriteRule ^categories/([^/\.]+)/([^/\.]+)/?$ index.php?url=product.php&cat_url=$1&prod_url=$2 [L] RewriteRule ^categories/([^/\.]+)/([^/\.]+)/recipes?$ index.php?url=recipes.php&cat_url=$1&prod_url=$2 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+\.php)/?$ index.php?url=$1 [QSA]This .htaccess works perfectly on my local MAMP server.When I test the CGI-Monitor in the control-center with an example file I get- cgi: File not present or has invalid modes (no output)The only file working now is index.phpThanks for your help!
.htaccess working locally, but not on 1and1 server
Create a .htaccess file with your php script, write a redirect into it for some file, and then call the file and check if it's redirected. Should be one of the most basic ways to check if .htaccess works.Edit: Not tested<?php $html1 = "test.html"; $html2 = "test2.html"; $htaccess = ".htaccess"; $string1 = "<html><head><title>Hello</title></head><body>Hello World</body></html>"; $string2 = "<html><head><title>Hello</title></head><body>You have been redirected</body></html>"; $string3 = "redirect 301 /test.html /test2.html"; $handle1 = fopen($html1, "w"); $handle2 = fopen($html2, "w"); $handle3 = fopen($htaccess, "w"); fwrite($handle1, $string1); fwrite($handle2, $string2); fwrite($handle3, $string3); $http = curl_init($_SERVER['SERVER_NAME'] . "/test.html"); $result = curl_exec($http); $code = curl_getinfo($http, CURLINFO_HTTP_CODE); if($code == 301) { echo ".htaccess works"; } else { echo ".htaccess doesn't work"; } ?>
as title says I am looking for a PHP function to check if you can use .htaccess file on your server.What should I test for ?Option 1:Maybe ifmod_rewritemodule is installed ?Option 2: Check out if "AllowOverride None" presented in 'httpd.conf'.Thank you for your suggestions, code will help too ;)
php script(function) to check if .htaccess is allowed on server
Flags should be listed together separated by comma -- exactly the same way how it's done in RewriteRule itself:RewriteCond %{HTTP_HOST} ^example\.com [OR,NC] RewriteCond %{HTTP_HOST} ^123\.45\.67\.89 RewriteRule (.*) http://www.example.com/$1 [R=301,L]Another approach:RewriteCond %{HTTP_HOST} ^(example\.com|123\.45\.67\.89) [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L]
I would like to know if I can do this redirect where I have the domain: example.com be non case sensitive along with the or statement for the IP. Both work indpendently of each other but not together?RewriteCond %{HTTP_HOST} ^example\.com [OR] [NC] RewriteCond %{HTTP_HOST} ^123\.45\.67\.89 RewriteRule (.*) http://www.example.com/$1 [R=301,L]
htaccess redirect using OR and NC
Put this into your .htaccess<FilesMatch "\.(?i:jpg|gif|png)$"> Header set Content-Disposition attachment </FilesMatch>Make sure you havemod_headersinstalled and enabled.
I have been trying to force images to download using PHP Headers but there have been multiple problems.So, instead, how can I use.htaccessso that when I link to an image like:<a href="wallpapers/image.jpg">Download</a>...instead of opening that file in browser, the file is actually downloaded and saved to the user's computer.I am already using .htaccess in my project to rewrite URLs if that affects anything.
Force a file or image to download using .htaccess
This thread on the Dreamhost support forumlooks like it has the info you want.
I would like to compress all css and js on my Dreamhost site, I have found suggestions on the web but none of them work. Does anyone have a working example of gzip running on a Dreamhost site?
How do I enable gzip on Dreamhost?
FilesMatchdoesn't work with directories.Create a new.htaccessinsideroot/attachment/as<FilesMatch ".*"> Order Allow,Deny Deny from All </FilesMatch>Redirect rules specified in a parent directory.htaccessapply to its sub-directories as well. In case, these access rules do not work the same way, just move the.htaccessdirectly intofilesdirectory.
I am trying to deny everyone to download anything inside the "attachment" directory.My website structure is:public_html -img -css -root --attachment ---(numeric id) ----(files) -jsWhat I am trying to do is, to deny access to root/attachment//I tried many things, but I don't know why, I cannot get it working, my last tried was:.htaccess - on main directory.<FilesMatch "root/attachment/.*/.*"> Order Allow,Deny Deny from all </FilesMatch>Any ideas? Thank you very much :)
.htaccess, deny to download files within a directory
As you correctly noted the header can be set in php:<?php header('X-UA-Compatible: IE=edge,chrome=1');It can also be set in.htaccesslike so:<IfModule mod_headers.c> Header set X-UA-Compatible "IE=Edge,chrome=1" # mod_headers can't match by content-type, but we don't want to send this header on *everything*... <FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webm|webp|woff|xml|xpi)$"> Header unset X-UA-Compatible </FilesMatch> </IfModule>(copied from theHTML5 Boilerplatetemplate)However, if you are setting these headers and finding that IE still defaults to quirks-mode then I'd be inclined to suggest that there is something else at work. Have you ensured that your pages include a validdoctype? Notably one thatisn'tof the HTML 4.01 flavour.
actually i'm having a problem with a website in IE which is not on intranet and the "always show pages in compatibility mode is not activated" but it still opens in quirks mode sometimes, despite adding<meta http-equiv="X-UA-Compatible" content="IE=edge"/>I have red that i can send this compatibility order in an HTTP Header or in htaccessMy problem is that i have searched on how to send an HTTP header and actually found no clue, and btw i'm a php developer just in case this information was necessary.I would really appreciate if someone could provide me what's needed to add (for both, or for one at least) and how/where to add it, i have been looking for the whole week and it's quiet urgent to find the fix so soon !Is this way to send it as an HTTP header as a first line in the page is right ?<?php header('X-UA-Compatible: IE=edge'); ?>(I have just found it)I really appreciate any help can be provided and i'm thankful in advance.
X-UA-Compatibility with HTTP Header
The PHP SDK expects the 'state' field to be in $_REQUEST (I believe as a GET param) after the redirect before you can exchange the 'code' for an access token. From base_facebook.php:protected function getCode() { if (isset($_REQUEST['code'])) { if ($this->state !== null && isset($_REQUEST['state']) && $this->state === $_REQUEST['state']) { // CSRF state has done its job, so clear it $this->state = null; $this->clearPersistentData('state'); return $_REQUEST['code']; } else { self::errorLog('CSRF state token does not match one provided.'); return false; } } return false; }Your RewriteRule may be stomping on that param.
I did some searches and I didn't find anything that was related to my problem.I'm currently trying to implement a Facebook login to my website and I'm having problems with the login authentication due to htaccess mod rewrite URLs?The code works perfectly and I get logged in if I use it without the mod rewrite rules like:domain.com/view_webhosting.php?webhosting=nameBut as soon as I go over to the mod rewrite URLdomain.com/webhosting-name/Then it just doesnt work and throws a error "CSRF state token does not match one provided."in the htaccess file it looks like thisRewriteRule ^webhosting-([a-z_0-9-]+)/$ /view_webhosting.php?webhosting=$1 [L]Anyone have a solution to a problem like this? I am using Facebook SDK v3.1.1
Problem with Facebook login not matching CSRF state token
Anything after the#is a fragment, and willnotbe sent to the webserver. You cannot capture it at any point there, you'll have to use a client-sided approach to capture those.
I've seen a number of examples of the opposite, but I'm looking to go from an anchor/hash URL to a non-anchor URL, like so:From: http://old.swfaddress-site.com/#/page/name To: http://new.html-site.com/page/nameNone of the examples athttp://karoshiethos.com/2008/07/25/handling-urlencoded-swfaddress-links-with-mod_rewrite/have functioned for me. It sounds likeREQUEST_URIhas the/#/stuffin it, but neither me nor my Apache (2.0.54) see it.Any ideas, past experiences or successes?
How to Detect and Redirect from URL with Anchor Using mod_rewrite/htaccess?
IndexOptions Charset=UTF-8
I've enabled directory listing of a folder under public_html, by adding:Options +Indexesin the .htaccess file.However, some files are not listed correctly by default, as some filenames are in Chinese (UTF-8 encoded). I can see the filenames if the change the browser's charset encoding to UTF-8.How can I let the browser see the filenames in UTF-8 by default? Is there a parameter to add in the .htaccess? I tried adding:AddDefaultCharset utf-8in the .htaccess file but it does not change anything.Thanks~
how to control charset of directory listing via .htaccess?
The following rule rewrites www.example.com and www.example.com/ to www.example.com/app/webroot/RewriteRule ^$ app/webroot/ [L]This rule rewrites www.example.com/* to www.example.com/app/webroot/*RewriteRule (.*) app/webroot/$1 [L]I would throw out your rule and update the wildcard regex in the last rule,(.*), so that it matches any string which doesn't start withbildbank. Something like this might do the trick:RewriteRule ((?!bildbank).*) app/webroot/$1 [L]This converts the following strings:cake cake.htm cake/test bilder bilder.htm bilder/test bildbank bildbank.htm bildbank/test.. into:app/webroot/cake app/webroot/cake.htm app/webroot/cake/test app/webroot/bilder app/webroot/bilder.htm app/webroot/bilder/test bildbank bildbank.htm bildbank/test.. therefore, excluding yourbildbanksubdirectory.
I have a cakephp installation in the root of my domain. Now it turns out I need to put another app in there that will reside in a subdirectory. How do I disable the controller/model redirection in cake for just this directory?The current .htaccess in the root folder looks like this:<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>I've tried modifying it like this, but to no avail:<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^bildbank$ /bildbank/ [L] RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>I am aware that this is a bit of a hack, but there's no way I can get the second app to play nice with cake.
How do I disable CakePHP rewrite routing for a single folder so it can be used as a location for a second application?
If all you need is to exclude requests with/pagein the URI-path, you may try this:RewriteCond %{REQUEST_URI} !/page [NC] RewriteRule ^(.*)/[0-9]+/?$ /$1/? [L,R=301]
I added the folowing code to main .htaccess# BEGIN RewriteEngine On RewriteBase / RewriteRule ^(.*)/[0-9]+/?$ /$1/? [L,R=301] # ENDI'd like to add an exception to any link ended with .../page/
Add an exception to .htaccess RewriteRule
You can't match against the query string within aRewriteRule, you need to match against the%{QUERY_STRING}variable in aRewriteCond. However, if you want to just append the query string, you can just use theQSAflag:RewriteRule /cia16(.*) /cia/$1?CIA=16 [QSA]The URI:/cia16/steps.php?page=1would get rewritten to/cia/steps.php?CIA=16&page=1. If for some reason, you need thepage=1beforetheCIA=16, then you can do something like this:RewriteRule /cia16(.*) /cia/$1?%{QUERY_STRING}&CIA=16
I don't understand why I always have such a massive problem with rewrite rules, but I simply want to append to the query string if it exists and add a?if it does not. I actually don't care if the URL is changed in the browser or not -- it just has to load the correct target page.RewriteRule /cia16(.*)\?(.*) /cia$1?$2&CIA=16 RewriteRule /cia16(.*) /cia/$1?CIA=16If I go to/cia16/steps.php?page=1it actually gets rewritten to/cia/steps.php?CIA=16-- that is it seems accept the query string part is not even considered part of the URL for the purposes of the rewrite.What do I have to do to get the rewrite to work properly with an existing query string?
Rewrite to append to query string
In the htaccess file in your document root, you can include these rules:RewriteEngine On # you can add whatever extensions you want routed to your php script RewriteCond %{REQUEST_URI} \.(doc|zip|pdf)$ [NC] RewriteRule ^(.*)$ /download-file.php?filename=$1 [L]Then in yourdownload-file.php, you can display whatever you need to display and the download link, which your php script can just immediately serve the file usingphp's readfile() (see link for examples)
I have.docand.zipfiles in download directory on my server. whoever visit my site page (download-file.php)only those user should be able to download these files and other should not.I am trying to achieve above but no luck...I am still able to put direct file address (http://example.com/sample.doc) in browser and I am able to download which I don't want..even someone else giving link to above file on any website then also download should not happen.Could any one please share some idea..how i should achieve this.Thank you in advance.
DENY direct download of file using php
Use this line:RedirectMatch 302 ^/$ /home/To make sure only root is redirected to/home/
I have been asked by my client's SEO agency to perform a 302 redirect on the home page of their website to the more specific URL of the same page i.e.(not the slash root version). This is a WordPress site running on Apache2 with .htaccess file in place. I need to achieve the following:Redirect from:http://www.example.com/302 redirect to:http://www.example.com/home/I thought I could do this:redirect 302 / http://www.example.com/home/But of course this redirects everything to that url. So I guess I need some sort of regular expression but not sure how to produce the desired effect? Could anyone point me in the right direction? Any feedback greatly appreciated. ;)
301/302 redirect from slash root to specific home page url
Can you try this?([a-z-\s]+)RewriteRule ^([0-9]+)$ /html/index.php?phone=$1 [QSA,L] RewriteRule ^([A-Za-z-\s]+)$ /html/index.php?lastname=$1 [QSA,L] RewriteRule ^([A-Za-z-\s]+)/([A-Za-z-\s]+)$ /html/index.php?lastname=$1&name=$2 [QSA,L]
I wrote a local name/phone/address search engine for my city.Users must be able to quick-access the results by going to either of these urls:search by numberhttp://domain.com/5554651search by lastnamehttp://domain.com/smithhttp://domain.com/smith%20johnsonsearch by lastname and first namehttp://domain.com/smith/andrewhttp://domain.com/smith%20johnson/mary%20elizabethThis is my current .htaccess config:# Smart links RewriteRule ^([0-9]+)$ /html/index.php?phone=$1 [QSA,L] RewriteRule ^([A-Za-z-]+)$ /html/index.php?lastname=$1 [QSA,L] RewriteRule ^([A-Za-z-]+)/([A-Za-z-]+)$ /html/index.php?lastname=$1&name=$2 [QSA,L]That works pretty well, except if the user includes a space in the lastname and/or first name. Also, no numbers can be used when searching for names.Any ideas on how to allow spaces in the url? Thanks!
Using spaces in URL and .htaccess
From thedocumentation:Context: server config, virtual hostso the answer is "no", I'm afraid.
How can i use RewriteMap directive in htaccess file? When i put it there i get "RewriteMap not allowed here" error.I know this error will disappear when put it in httpd.conf or virtualhost configuration file. But i want to know is it possible to put it in htaccess or not?
use RewriteMap in htaccess file
Sample rules for .htaccess (once you make sure mod_rewrite is enabled):RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.php?page=$1 [L]These rules match any URL that isn't an already existing file and passes it to your script.
I am working on a new project, I want to create SEO friendly URL's for this site likemysite.com/first_content, mysite.com/second_content. URL's must be dynamic which means URL's must related to the content title. How can I done this ? Is is possible to use htacess, ?Thanks
php : SEO friendly urls
FromSelenium FAQ(which is down at the moment):How do I use Selenium to login to sites that require HTTP basic authentication (where the browser makes a modal dialog asking for credentials)?Use a username and password in the URL, as described in RFC 1738: Test Typeopenhttp://myusername:[email protected]/blah/blah/blahNote that on Internet Explorer this won't work, since Microsoft has disabled usernames/passwords in URLs in IE. However, you can add that functionality back in by modifying your registry, as described in the linked KB article. Set an "iexplore.exe" DWORD to 0 in HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE.If you don't want to modify the registry yourself, you can always just use Selenium Remote Control, which automatically sets that that registry key for you as of version 0.9.2.
I am using WebDriver (Selenium2) with Java on linux. I am using WebDriver to auto fill form and submit it. I am facing problem with htaccess sites i.e., I am not able to access htaccess site through WebDriver.Can anyone help me out in this regard?Thanks in advance, Sunil
Getting Selenium to login via .htaccess popup
move all content includeindex.phpin each public directory to Store, Blog and Newspaper respectively. and change the following line:require __DIR__.'/../bootstrap/autoload.php'; $app = require_once __DIR__.'/../bootstrap/start.php';torequire __DIR__.'/bootstrap/autoload.php'; $app = require_once __DIR__.'/bootstrap/start.php';good luck.EDIT: Sorry. You have to edit/bootstrap/paths.phpas well, change'public' => __DIR__.'/../public',to'public' => __DIR__.'/../',
I'm trying to upload multiple Laravel 4 projects to my web server, not my development server. Each laravel 4 app is housed in their own subdirectory. How should my file structure be? I've searched around for a htaccess to remove the /public from the url but i've been unsuccessful. this server is for testing purposes only, it allows others to follow along as the project is being built. I know their are major security issues with leaving the laravel base structure in these directories, but again they are just for testing purposes and when the projects are complete they are removed and placed on their own hosting server. This is my file structure now:-public_html/ main website html files -Test Site Subdirectory Folder -subdirectoryFolder -Store/ -laravel app 1 -blog/ -laravel app 2 -newspaper -laravel app 3if i install laravel app in each subdirectory folder (www.testsite.com/Store,www.testsite.com/blog,www.testsite.com/newspaper) each application works, however I am trying to remove the public at the end of the url,www.testsite.com/Store/publicis what is shown in the browser. Any help with this problem is greatly appreciated. Thank you.
install multiple Laravel 4 projects to sub directories
Lwill still be needed as Last flag is for marking end of each rewrite rule. Ordering of rules is also important. Change your code to this:<VirtualHost *:80> ServerName datingjapan.co ServerAlias *.datingjapan.co DocumentRoot /var/www/html/datingjapan.co RewriteEngine on RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*) http://www.%{HTTP_HOST}$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.*)$ /index.php?/$1 [L,QSA] </VirtualHost>
I have a 2 sets of rewrite rules. This is the Virtual Host:<VirtualHost *:80> ServerName datingjapan.co ServerAlias *.datingjapan.co RewriteEngine on RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*) http://www.%{HTTP_HOST}$1 [R=301,L] DocumentRoot /var/www/html/datingjapan.co </VirtualHost>and this is the .htacess<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule>I have been trying to add the .htaccess to the Virtual Host so I can remove the .htaccess file - below is an example, but I get the site to show:<VirtualHost *:80> ServerName datingjapan.co ServerAlias *.datingjapan.co RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.*)$ index.php?/$1 RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*) http://www.%{HTTP_HOST}$1 [R=301,L] DocumentRoot /var/www/html/datingjapan.co </VirtualHost>I understand the [L] means last rule to match so I have removed that but it still doesn't work.What am I missing here? I've tried reversing the rules.thankyou
Apache Multiple Rewrite Rules
This is caused bymod_dir and the DirectorySlash directive. It will automatically 301 redirect requests for a directory that's missing the trailing slash. This fixes an information disclosure security concern (described in the above link) which lists the directory contents even when there's an index file (e.g.index.php). So if you turn this functionality off,be very careful about your directories. If you've got directory indexing turned off, then that's not so much of a concern.You can turn of directory slashes using:DirectorySlash OffYou can turn off directory indexing using the Options:Options -IndexesAnd then, you need to have your projects rulebeforeyour php extension rule:Options +FollowSymLinks -MultiViews -Indexes DirectorySlash Off RewriteEngine on RewriteRule ^projects$ /projects/index.php [L,E=LOOP:1] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^\.]+)$ $1.php [NC,L]
The following is my directory structureRoot/ index.php contact.php projects.php /index.php /project1.php /project2.phpI have rewrites in place to remove the .php extension from all file names. It works perfectly fine and I can accesswww.website.com/projects/project2.phpfromwww.website.com/projects/project2I also want to be able to accesswww.website.com/projects/index.phpaswww.website.com/projectsI have managed to write a rule which rewrites the url towww.website.com/projects/when i typewww.website.com/projectsHowever, I am not being able to get rid of the last trailing slash.Please note that I do not really understand much of this. Most of it is from what I have found on the internet. I have looked around a lot but not got anything to work till now.Here is the code:Options +FollowSymLinks -MultiViews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^\.]+)$ $1.php [NC,L] RewriteRule ^projects$ /projects/index.php [L,E=LOOP:1]
Removing The Trailing Slash from a directory in htaccess
The^xxx.xxx.x.xx$portion of yourRewriteCondis simply a regular expression. You can easily use groups to add more IP addresses:^(xxx\.xxx\.x\.xx|yyy\.yy\.y\.yy)$You will notice I have escaped all the.s with a backslash - this is because.has a special meaning in a regular expression, and it needs to be escaped if you want it to match only a literal.character.So your newRewriteCondwill look like this:RewriteCond %{HTTP:X-FORWARDED-FOR} !^(xxx\.xxx\.x\.xx|yyy\.yy\.y\.yy)$You can easily add more IP addresses, simply separate them with|characters.Please note, however, that this approach does not give you any real security. It would be easy to spoof a request to get past this. If you need security you should use SSL and a proper authentication system instead.
Hi i should only allow the particular ip address(which is HTTP:X-FORWARDED-FOR adresses) to access the files. I have done it by the followingOptions +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{HTTP:X-FORWARDED-FOR} !^xxx.xxx.x.xx$ RewriteRule ^$ http://xxx.xxx.x.xx/access_denie.php [R=301,L]Now i have to allow it for multiple ip for example yyy.yy.y.yy. How can i do it by using htaccess
Allow access in htaccess based on the HTTP:X-FORWARDED-FOR
The CI.htaccessshouldn't be in the application folder; it should be in the root of theSubDomainfolder. e.g./public_html/SubDomain/.htaccessAlso, in that.htaccess, you need to set theRewriteBase:<IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on RewriteBase /SubDomain RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1 [L] </IfModule>
In my CodeIgniter site (hosted on GoDaddy), navigating to any page but the index gives me this error:No input file specified.Googling around, it seems like the cause must have something to do with my .htaccess situation. The way this is set up, and maybe this can eventually change, is that my CI site is in a subdirectory of the main domain. The CI site and main domain each have their own .htaccess files. The CI htacess file is located in the applications folder:<IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /SubDomain/index.php?$1 [L] </IfModule>And here's the main htaccess file is two levels up from the CI one, reading thusly:RewriteEngine on RewriteCond %{SERVER_PORT} 80 rewriterule ^(.*)$ https://www.MainDomain.org/$1 [r=301,nc]I am afraid these two sets of re-write rules are conflicting with each other and I really have no idea what to do about it. I can alter either htaccess file and would really like to get them working together in peace and harmony. It's also possible, however, that this has nothing whatsoever to do with htaccess.
CodeIgniter site in subdirectory, htaccess file maybe interfering with htaccess file in main directory?
Try changing the last line to this:RewriteRule .* index.php [R=301,L]SeeApache mod_rewrite RewriteRule Directivethe section about flags.
I've notice in firebug that the non-www version of my magento store redirects to the www version using302. For SEO purposes I want it to redirect using301.How I tried to fix itI went to the System > Configuration > General > Web > Url Options and my setting Redirect to Base URL if requested URL doesn't match it is set to Yes (there are only 2 options: Yes or No)Imporantant notesI'm using Magento v1.4.0.1 My.htaccessfile contains the following, in regards to URL Rewrites:<IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteCond %{REQUEST_URI} !^/(media|skin|js)/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule .* index.php [L] </IfModule>How can I change the redirect method to301?
Magento redirects to base url using 302, how do I get it to use 301
You need to specify that your image rewrite rule is the last one in the row in order to prevent further rewriting. For that you simply specify[L]at the end of your image rewrite rule.RewriteEngine On RewriteRule /admin/images/(.*) /images/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.phpEDIT:Here is an explanation why the problem occurs (taken from the comments section in order to provide clarification).You see the original%{REQUEST_FILENAME}will never change no matter how many stages of rewriting are performed. That means that when the second rule is reached that variable will actually still point to the existing image (which is in/admin/images/) rather to the one being rewritten and non-existing (/images/). That's the reason why the second rule will always be applied and why the two conditional lines from the example are almost always the first ones to be used during rewriting.
The following is my directory structures:admin\ controls\ images\ media\ lib\ models\ views\ index.php .htaccessThe following is my .htaccessRewriteEngine On RewriteRule /admin/images/(.*) /images/$1 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.phpI want everything in /admin/images be equal to /images in root directory. For example:http://www.example.com/admin/images/example.pngwill be the same ashttp://www.example.com/images/example.pngProblem with my .htaccess is:It goes to index.php instead of mirroring admin/images to images/SolutionRewriteEngine On RewriteRule /admin/images/(.*) /images/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php
Redirect from one directory to another with mod_rewrite
If the VHost is really pointing to the same docroot for www.sub.domain.com and sub.domain.com, you can place a .htaccess-file with following content in the doc-root:RewriteEngine On RewriteCond %{HTTP_HOST} !^sub\.domain\.com$ [NC] RewriteRule (.*) http://sub.domain.com$1 [R=301,L]That will redirect all domains which are pointing to this docroot to sub.domain.comEDIT:For multiple Subdomains in one single .htaccess-file:RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.([^\.]*)\.domain\.com$ [NC] RewriteRule (.*) http://%1.domain.com$1 [R=301,L]This is untested from top of the head.
I have a variety of sites that are subdomain specific sites.http://sub.domain.comhttp://apple.domain.cometc.users occasionally complain that the site is not working and then i find out they went tohttp://www.sub.domain.comorhttp://www.apple.domain.comand are met with a server error page of sortswhat kind of htaccess magic do i need to turnhttp://www.sub.domain.com->http://sub.domain.comthanks*fwiw i did search through previous questions before asking and did not find my answer
removing www with htaccess file for subdomains
If you want to do this with .htaccess (or in Apache config), you can useApache module mod_headers, like this:Header set Cache-Control "no-transform" Header set Content-Type "application/xhtml+xml; charset=utf-8"A search onhtaccess set headergives you many more examples of this.
I code same lines all PHP programs at one of my projects. Is it possible to do this at .htaccess for a directory? And how?PHP codes:Header('Content-Type: application/xhtml+xml; charset=utf-8'); Header("Cache-Control: no-transform");Thanks any help. Best regards.Yusuf Akyol
Set HTTP header for all PHP scripts via .htaccess file
Bit long ago, but I'll answer the question anyway for those who come here by Google (like me). The answer is really simple:In your htaccess, remove the R=301 part (and the comma of course).R=301 means you do it via a 301 redirect. You don't want that
I want to be able to redirect a domain pointed to my webhosting to an external domain.For example, I have this in my .htaccess:RewriteCond %{HTTP:Host} ^(?:www\.)?mydomain\.example$ RewriteRule ^(.*)$ http://myexternal.example/site [R=301,NC]However, when I visit the domain, the URL in my address bar changes tohttp://myexternal.example/site.How can I redirect without changing the URL?Is there another way around this? Do I need to use a frame/iframe?
.htaccess redirect to external URL while hiding redirect
If you wont have to change your rules very often, you should put them in the httpd.conf and turn off overriding in the top directory your rules apply toAllowOverride NoneWith no overriding, your apache will not scan every directory for .htaccess files making less of an overhead for each request.Whenever you do have to change your rules, you will have to restart your apache server if you put it in your httpd.conf as opposed to them being instantly detected in .htaccess files because it reads them all on every request.You can easily do this using a graceful restart with the apachectl tool to avoid cutting off any current requests being served.apachectl gracefulIf you aren't going to turn override off, you might as well just use .htaccess only.Edit in response to your edit:Say you have a request for www.example.com/dir1/dir2/dir3/fileApache will look for a .htaccess file in all 3 of those directories and the root for rules to apply to the request if you have overriding allowed.
I need to do a url-rewriting job now.I don't know whether I should put the code into a .htaccess or httpd.conf?EDITWhat's the effecting range of .htaccess?Will it affect all requests or only requests to the specific directory it's located?
.htaccess or httpd.conf
Try out this:RewriteEngine on ErrorDocument 404 http://yoursitename.com/404page.phpAnd be sure that404page.phpexists on the root of your server and is trully called404page.phpnot404Page.phpBe carefull at the characters, this is key sensitive!
I have a custom 404 page called 404page.php , and I have the htaccess file with the line that I found should work (this is the only line I have in the .htaccess file)ErrorDocument 404 /404page.phpIt was working fine yesterday, but today I was optimizing images and some other stuff on the website, and when I reuploaded it, the htaccess didn't redirect to 404page.php anymore, but to a page that has this written:Not FoundThe requested URL /asfsdtg was not found on this server.Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.(I just typed asfsdtg to test if it was working).The website is uploaded online and I'm managing it through cpanel (I'm still a beginner). I searched for some solutions, I tried adding another line to .htaccess, then it looked like this:RewriteEngine on ErrorDocument 404 /404page.phpI even tried putting the location of the 404page.php as a local link, and the internet link, and it still gave me the weird error page.Does anyone have some idea whats happening? If you need more info that I didn't supply please tell me what more I can supply
htaccess not redirecting to custom 404 page
I wouldn't pass two parameters to your function, just treat it like an ID in both cases. You'll need to add a "slug" column to your db if you haven't already and make sure those values are unique just like an id. Then in your controller you can do something like this:public function getCampaignMap($id){ //look for the campaign by id first $campaignmap = Campaign::find($id); //if none is found try to find it by slug instead if(!$campaignmap){ $campaignmap = Campaign::where('slug','=',$id)->firstOrFail(); } return View::make('campaignmap.show', compact('campaignmap')); }You could also save yourself a query in some cases by checking to see if the id is numeric and then just look for it by slug if it's not numeric such as:public function getCampaignMap($id){ //look for the campaign by id if it's numeric and by slug if not if(is_numeric($id)){ $campaignmap = Campaign::find($id); }else{ $campaignmap = Campaign::where('slug','=',$id)->firstOrFail(); } return View::make('campaignmap.show', compact('campaignmap')); }
I would like to add niceSlugURL to my Laravbel Project. I currently am using ID numbers.My goal is to continue using Numbers but also to use Slugs for better SEO URL's. So either a Slug or an ID will load the proper page.Below is my currentRoutethat uses an ID number to load a record.// View Campaign Details/Profile/Map View Route::any("/campaign/{id}", array( "as" => "campaign/{id}", "uses" => "CampaignController@getCampaignMap" ));To be able to add Slug support in Laravel 4. I believe I need to add a slug database column to my campaigns table.How would I go about editing my Route to work with an ID number of a slug string?Also since I am only wanting to use slug on a couple sections of my application, how would I do my.htaccess for this, or is an.htaccess even required?
How to add slug and ID URL to Laravel 4 Route?
Unfortunately<Location>directive isn't allowed in.htaccess.But there is an alternate neat solution usingmod_setenvif.# set env variable SECURED if current URI is /c/sofas/ SetEnvIfNoCase Request_URI "^/c/sofas/" SECURED # invoke basic auth is SECURED is set AuthType Basic AuthName "My Protected Area" AuthUserFile /full/path/to/passwords Require valid-user Satisfy any Order allow,deny Allow from all Deny from env=SECURED
Is it possible to password protect a virtual directory (such as a wordpress category):/c/sofas/It looks like<Location /c/sofas/>would work in httpd_config, but not .htaccessIs it possible? Possibly with a mod_rewrite somewhere?
Password protect a virtual directory? - .htpasswd/.htaccess
Place the following in your.htaccessfile:RewriteEngine on # The two lines below allow access to existing files on your server, bypassing # the rewrite RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.php?p=$1 [QSA]You can then accesswhateverfromexample.com/whateverlike the following:$value = $_GET['p']; // "whatever"
I have a URL that will be something likeexample.com/index.php?p=testso that the PHP will load the test variable using$_GET['p']. The URL can already be simplified toexample.com?p=test; however, I wish to simplify this in my.htaccesstosite.com/test. How would i go about doing this?
.htaccess replace (rewrite) $_GET variables in PHP URL
So the issue you are having is that your or block right now applies to both the HTTPS and the HTTP case. You need untangle this (well actually - you could also use 'satisfy any' - but that is a bit messy in this case).An easy to debug/understand approach is to go to a structure like:<VirtualHost *:80> ... RewriteRule ^/foo/bar/?(.*)$ https://myserver.tld/foo/bar/$1 [R,L] # and to guard against typo's... <Directory /foo/bar/> deny from all </Directory> </VirtualHost> <VirtualHost *:443> ... <Directory /foo/bar/> BasicAuth .. etc. allow from all </Directory> </VirtualHost>and take things from there.Dw.
I am wondering what the best way to force HTTPS authentication is.When I have this in my .htaccess file:AuthType Basic AuthName "Developer" AuthUserFile /usr/local/etc/apache22/passwords/passwords Require user davidAuthentication works, but it authenticates over port 80, sending the password in the clear.So I figured I would add a Redirect Rule to redirect all non-HTTPS requests to equivalent HTTPS requests:RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteBase /~david/ RewriteRule ^(.*)$ https://myserver.tld/~david/$1 [R,L]This also works, but it first authenicates on port 80, then redirects, then authenicates again on port 443. I do NOT want to authenticate on port 80, because the password will be sent in clear text. I have not been able to figure out a good way to redirect immediately to HTTPS, and then authenicate.The only way I could figure how to do this is by doing this:AuthType Basic AuthName "Developer" AuthUserFile /usr/local/etc/apache22/passwords/passwords Require user david ErrorDocument 403 /403.php SSLRequireSSLAnd having a 403.php PHP script on the / of my server:<?php header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>This is the desired behavior. It requires SSL, so when you try to access the directory on port 80, it spits out a custom error document, and that document to redirects the page to HTTPS.This seems like a kludge. Is there a better way to accomplish this?
How to force HTTPS on a directory AND force HTTPS authentication
Try something like this:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ bio/bio.php?q=$1 [L]First line will skip the RewriteRule if it finds a matching physical file; second line will skip it if it finds a matching directory. The third line is the rewrite rule that will be executed if the preceding condtions are met.
I have the following htaccess file:RewriteEngine On RewriteRule ^([^/]*)$ /bio.php?bio=$1 [L]I need it to do the following:Get the following rewritten URL:http://www.website.com/john-smithto go to /bio.php?bio=john-smith (that kind of works at the moment)If there is already a folder (eg /about-us/) then show the file in that instead. At the moment it does but it adds ?bio=about-us on the end.Ideally if possible work with & without the trailing slash.Any help much appreciated.Thanks
Rewrite if folder doesn't exist?
Try separating out the www and the trailing slash check. This is tested and hopefully working for you. You didn't say if you're running placing at domain root or in a subdirectory - usually good info when asking for help with htaccess.RewriteEngine On # Assuming you're running at domain root. Change to working directory if needed. RewriteBase / # # www check # If you're running in a subdirectory, then you'll need to add that in # to the redirected url (http://www.mydomain.com/subdirectory/$1 RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L] # # Trailing slash check # Don't fix direct file links RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ $1/ [L,R=301] # # Finally, forward everything to your front-controller RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php [QSA,L]To debug, comment out the individual sections and see what is/isn't working.
I'm using my htaccess file with mod_rewrite to create clean urls like this:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] </IfModule>I would also like to force the site to have the 'www' subdomain and most importunately add a trailing slash if the url doesn't have one.I am an absolute noob with mod_rewrite and I've tried accomplishing this on my own by combining other code I found on google (sad I know), but I always end up with a 500 error.Here's the code I found for force www:<IfModule mod_rewrite.c> Options +FollowSymLinks RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC] RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L] </IfModule>Thanks for your help.
htaccess add trailing slash and force www with clean urls
When you're using .htaccess you don't have the leading slash:RewriteEngine On RewriteRule ^uk/page2/(.*)/$ /uk/page2/index.php?pg=$1
I'm developing a web site containing 3 pages (Home, page2, page3) ... in the second page there is a navigation bar, with 4 items (subpage1, subpage2, ...), that I use to replace the content of the page 2 with url variables! In other words, the second item of the navigation bar in page2 points to:http://localhost/uk/page2/index.php?pg=subpage2the item 3 point to:http://localhost/uk/page2/index.php?pg=subpage3Now I would like to use more friendly urls via.htaccess!I've written this:RewriteEngine On RewriteRule /uk/page2/(.*)/$ /uk/page2/index.php?pg=$1in the.htaccessplaced in the root!But doesn't work! Please help!!!
Why this RewriteRule doesn't work?
None of those things will make a difference if yourownershipis wrong. The reason wordpress can't write to it is because the file is probably owned by another user instead of web server. I've seen this numerous times.To fix this issue, first change the permission back to amoresecure permission using this from the command line.chmod 644 .htaccessThen change the ownership/group of the .htaccess file to web server user.For CentOS/RHELchown apache: .htaccessFor Ubuntu/Debianchown www-data: .htaccessNow wordpress should be able to right to this file.
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.This question does not appear to be abouta specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic onanother Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.Closed8 years ago.Improve this questionI have Wordpress running on a dedicated centos server with Buddypress installed . Buddypress requires pretty permalinks. Therefore I changed i to /%postname%.Somehow it did not work because Buddypress is not working correctly and Wordpress suggests to create the .htaccess myself :"If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press CTRL + a to select all."I have tried every hint I found but somehow it does not work. Here is a list:mod_rewirte is enabled.htaccess was created and filled with wordpress suggested information.htaccess was set to chmod 777FollowSymLinks and AllowOverride All was set in the httpd.confIs there anything else I can do?Thanks in Advance
How to make .htaccess writeable for wordpress? [closed]
in your main folder try this: (for you this would be the silex folder)<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ web/$1 [QSA,L] </IfModule>and in the web folder:<IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /web/ RewriteRule ^(.*)$ /$1 [L,R=301] </IfModule>
I have a working path on my Apache2 localhost (linux):http://localhost/lab/silex/web/index.php/hello/nameI want to become:http://localhost/lab/silex/hello/nameNow I have Rewrite mode enabled and tested.I have placed my .htaccess file in my silex/web folder:<IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteBase /web/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ index.php [L] </IfModule>I still cannot see the clean url working.
Configure .htaccess to work on a PHP Framework (Silex)
It looks like you have your htaccess file in your document root on your server, and in themysitedirectory on localhost. Since the location of the htaccess file is pretty important on how it routes URIs, you need to make it indifferent to the location of the file. You can do this by extracting the path info from your condition instead of the URI that's passed into the rule to match against:RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?) RewriteRule ^ /%1 [R=301,L]The%{THE_REQUEST}variable is the first line of the actual HTTP request, which looks something like:GET /path/index.php HTTP/1.1The pattern first matches any number of possibleMETHODS(GET, POST, HEAD, etc), then it creates a grouping of the URI path that'sbeforetheindex.php, then ends the matching, since we don't really care what's after theindex.php.
I'd written this code for301 redirectRewriteCond %{THE_REQUEST} ^.*\/index\.php\ HTTP/ RewriteRule ^(.*)index\.php$ /$1 [R=301,L]It is working well in case if I do visit my site ashttp://mysite.com/index.php, it redirects me tohttp://mysite.comBut on mylocalhostif I try to visitindex.phpaslocalhost/mysite/index.phpit redirects me tolocalhost.How could I solve this problem? Is the code written above is correct?
remove index.php url rewriting .htaccess
Note: This information was taken nearly verbatim fromanother website, I thought it explained the issue well and I highly suspect this is the problem:Using php_flag or php_value in .htaccess filesSome PHP scripts suggest using "php_value" or "php_flag" commands in .htaccess files, as in this example:php_value include_path ".:/usr/local/lib/php" php_flag display_errors Off php_value upload_max_filesize 2M php_value auto_prepend_file "./inc/library.php"However, some servers run PHP in "CGI mode" (not as an Apache module), so you can't use "php_value" or "php_flag" commands in .htaccess files. If you try to do so, you'll see an "internal server error" message.You can modify your php.ini file to get the same effect, though. In fact, modifying php.ini is actually more flexible than using php_value or php_flag: there are many things you can't override using .htaccess files, but you can override almost any PHP setting in the php.ini file.To get the same effect as the .htaccess lines above, you would simply add these lines to your custom php.ini file:include_path = ".:/usr/local/lib/php" display_errors = Off upload_max_filesize = 2M auto_prepend_file = "./inc/library.php"Note: Some systems will require quotes around the paths, and some must not use quotes.
My .htaccess is as follows:Options +FollowSymLinks RewriteEngine On RewriteBase /school RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1 RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1 php_value auto_prepend_file ./inc/library.php ErrorDocument 404 /school/index.php?page=404As of the./, I read that indicates a relative path.
.htaccess php_value auto_prepend_file makes 500 error. How can I fix this?
You will need to enable mod_proxy in your Apache config for that. Once mod_proxy is enabled, enable mod_rewrite and .htaccess throughhttpd.confand then put this code in your.htaccessunderDOCUMENT_ROOTdirectory:Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.exaple\.cz$ [NC] RewriteRule ^(hu)/?$ http://www.exaple.$1 [L,P,NC]
All i want to do is to rewrite url from www.exaple.hu to www.exaple.cz/hu. So under address www.exaple.cz/hu is displayed content from adress www.exaple.hu.So when user type www.exaple.cz/hu, user isnotredirected to www.exaple.hu but content from www.exaple.hu is displayed under domain www.exaple.cz/hu (so in adress bar is www.exaple.cz/hu).
htaccess rewrite without redirect
glob()does list "hidden" files (files starting with.including the directories.and..), but only if you explicitly ask it for:glob(".*");Filtering the returnedglob()array for.htaccessentries withpreg_grep:$files = glob(".*") AND $files = preg_grep('/\.htaccess$/', $files);The alternative to glob of course would be just usingscandir()and a filter (fnmatchor regex):preg_grep('/^\.\w+/', scandir("."))
Simple question - How to list.htaccessfiles usingglob()?
PHP glob() doesnt find .htaccess
Try this:RewriteEngine On RewriteBase / RewriteRule ^(.*)\.(jpg|png|jpeg|gif)$ watermark/watermark.php?image=$1.$2 [NC,L]
I've written a PHP class to add a watermark to an image, it works great when accessed via URL directly. I would like to "redirect" every image to my URL like so:http://www.mysite.com/img.jpgto thishttp://www.mysite.com/watermark/watermark.php?image=http://www.mysite.com/img.jpgBasically what I want is to pass the src attribute specified in the HTML to the image variable. I'm currently struggling with my.htaccessfile and I can't get it working, here it is:Options +FollowSymLinks RewriteEngine On RewriteRule ^([^_].*\.(gif|jpg|png))$ /watermark/watermark.php?image=$1 [L]Looking forward to your replies and thanks in advance!
.htaccess image redirect
The other answers that say you have to absolutize the paths are correct. If you are working in a subfolder, there are two things that you can/should do to help:1) UseRewriteBasein your htaccess fileRewriteEngine on RewriteBase /framework/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)/?$ index.php?url=$1 [QSA,L]2) Create a constant in your framework that has that same pathdefine('FULL_PATH', '/framework');Then each time you create a URL in html, make sure you do something like<a href="<?= FULL_PATH ?>/your/remaining/path">It's a little bit of extra work to think about this each time you create a URL on the page, but it will serve you well in the long run.
I have a custom PHP framework in which everything after the domain is sent to PHP as a $_GET variable, like so:RewriteRule ^(.*)$ index.php?page_request=$1 [QSA,L]All routing is done by a router file. For example,http://domain.tld/pagegets sent tohttp://domain.tld?page_request=home.However, if I have a directory-like structure (i.e.http://domain.tld/page/), the request is sent, but anyrelative URLs in the HTMLare now relative to/page, even though we're still in the root level in the domain.To clarify:Going tohttp://domain.tld/pageand requestingres/css/style.cssin HTML returns a stylesheet.Going tohttp://domain.tld/page/and requestingres/css/style.cssreturns an 404 error, because thepage/directory doesn't actually exist.What's the best way to work around this? This seems really simple, but I'm not quite good enough with .htaccess yet to do it off the top of my head. Thanks for any answers in advance.Edit: Also, my .htaccess file contains:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-dEdit #2: Yes, I know about using the leading /.However, I can't do that with this particular website, because it's a subfolder on a server, so linking to/would go to the root of the server and not the site.If I put/subfolder/cssfor every link on the site, that would not only get tedious, but also problematic were the subfolder to change. Is there a better way to work around this?
Relative URLs with .htaccess
Option 1:(site.com/index.php?var1=A&var2=B&varN=n):Options +FollowSymLinks -MultiViews RewriteEngine On # do not do anything for already existing files RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule .+ - [L] RewriteRule ^([^/]+)/?$ index.php?p1=$1 [QSA,L] RewriteRule ^([^/]+)/([^/]+)/?$ index.php?p1=$1&p2=$2 [QSA,L] RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?p1=$1&p2=$2&p3=$3 [QSA,L] RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?p1=$1&p2=$2&p3=$3&p4=$4 [QSA,L]1. You had[NC]flag ... so there were no need to haveA-Zin your pattern.2. Instead of[a-zA-Z0-9_-\+\=\&]or[a-zA-Z0-9_-]I use[^/]which meansany character except slash /.3.[QSA]flag was added to preserve existing query string.Option 2:(site.com/index.php/A/B/n/):Options +FollowSymLinks -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) index.php/$1 [L]In reality, if you do not plan to show that URL anywhere (like, 301 redirect etc), the last line can easily be replaced byRewriteRule .* index.php [L]-- you will look for original URL using$_SERVER['REQUEST_URI']in your PHP code anyway.
I have an index file that builds content based onnPATH_INFO variables.Example:site.com/A/B/n/should use index.php at either:site.com/index.php?var1=A&var2=B&varN=n - or - site.com/index.php/A/B/n/instead of:site.com/A/B/n/index.php || which doesn't exist ||So far I've tried a number of variations of:RedirectMatch ^/.+/.*$ /with no success.I have an inelegant and unscalable solution here:RewriteEngine On RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?p1=$1 [NC,L] RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?p1=$1&p2=$2 [NC,L] RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?p1=$1&p2=$2&p3=$3 [NC,L] RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?p1=$1&p2=$2&p3=$3&p4=$4 [NC,L]Problems with this solution:Inelegant and unscalable, requires manual line for each subdirectoryFails with non alphanumeric characters (primarily +,= and &) ex. site.com/ab&c/de+f/ (note, even changing the regex to ^([a-zA-Z0-9_-\+\=\&]+)/?$ does little to help and actually makes it error out entirely)Can you help?
How can I redirect all sub-directories to root using htaccess or httpd.conf?
This should do what you wanted. I also added in a "don't redirect if this file exists", since I wasn't sure what was in your existing directories. You can try removing it by taking out the secondRewriteCondif you don't want it, but I think it's probably necessary to some extent.RewriteEngine On # Check if the requested path is not a real file or a # real directory RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f # If the current request doesn't start with "blog", and # it's not a real file or directory based on the above # conditions, add "blog" to the front of the request, and # mark an environment variable that indicates we'll need # to redirect RewriteRule !^blog blog%{REQUEST_URI} [E=CHANGED:TRUE] # Check if the host doesn't start with "www.", or if we've # marked the change variable above, since in either of those # cases we need to perform a redirection (We do it this way, # since we'll at most send one redirect back to the client, # instead of the potential two we might send if we didn't # combine the checks) RewriteCond %{HTTP_HOST} !^www\. [OR] RewriteCond %{ENV:CHANGED} =TRUE # Capture the non-"www." part of the host, regardless of # whether or not the "www." is there RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ # Redirect anything to the corrected URL, using the # backreference from the above condition, and the entirety of # the requested path (possibly modified by the above RewriteRule) RewriteRule ^.*$ http://www.%2/$0 [R=301,L]
Any request towww.example.com/*must be redirected towww.example.com/blog/*If nowww.prefix, add it.Importantly, if there exists any directory matching the request URI, don't redirect.Example:(www.)example.com/<request>->www.example.com/blog/<request>except<request> === <dirname>Following the above 3 conditions, how do I code a .htaccess? Please help! Thx ;-)
.htaccess: Redirect all requests to a subdirectory except if an exact directory exists
This seems to work (but I have to set the status code in PHP)RewriteEngine on RewriteCond %{REQUEST_URI} !^/static/.*$ RewriteCond %{REQUEST_URI} !^/media/.*$ RewriteRule .* down.php [L]and in down.php<?php header('HTTP/1.1 503 Service Temporarily Unavailable',true,503); ?>Any problems with this? My main concerns are what user's see (which is why i keep static content) and what search engines see (the 503 status code).
I was trying to install this .htaccess to notify my users of site maintenance. It seems the first [L] isn't working and the second rewrite is doing everything.How do you guys do site maintenance messages?RewriteEngine on RewriteRule ^s/down$ index.html [L] RewriteRule ^(.*)$ http://metaward.com/s/down [R=302,L]
Rewrite rule for "site down" pages
No,.htaccessfiles are only read from the PHP httpd module.
I'm investigating the best place to set my error logging options, and it seems the most reliable place would be in .htaccess in the script subdirectory. But this particular script is run via cron, and therefore via command line.Do php_value settings made in .htaccess affect scripts that are not run through the web server?
Do .htaccess php_value settings affect scripts run at command line?
One approach is to rewrite everything to a handling scriptRewriteEngine on RewriteBase / # only rewrite if the requested file doesn't exist RewriteCond %{REQUEST_FILENAME} !-s # pass the rest of the request into index.php to handle RewriteRule ^(.*)$ /index.php/$1 [L]so if you have a request tohttp://yourserver/foo/bar/what you actually get is a request tohttp://yourserver/index.php/foo/bar- and you can leave index.php to decide what to do with /foo/bar (using $_SERVER['PATH_INFO'] -tom)You only need to modify .htaccess the first time. All future requests for inexistent files can then be handled in PHP.You might also findthe docs for mod_rewriteuseful - but keep it simple or prepare to lose a lot of sleep and hair tracking down obscure errors.
I'm coding a small CMS to get a better understanding of how they work and to learn some new things about PHP. I have however come across a problem.I want to use mod_rewrite (though if someone has a better solution I'm up for trying it) to produce nice clean URLs, so site.com/index.php?page=2 can instead be site.com/toolsBy my understanding I need to alter my .htaccess file each time I add a new page and this is where I strike a problem, my PHP keeps telling me that I can't update it because it hasn't the permissions. A quick bit of chmod reveals that even with 777 permissions it can't do it, am I missing something?My source for mod_rewrite instructions is currentlythis page hereincase it is important/useful.
mod_rewrite, php and the .htaccess file
After making a big fuss with the technical team of my hosting provider, they confirmed my .htaccess file was not being uploaded via my FTP client. It looks like I should have added it to the dist folder after the build. The code for the .htaccess file they added is just the same as one of the versions I tried before and it works fine:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </IfModule>
I know a lot of people ask this, but I have looked at all the answers and nothing is working.I am sure the problem is I need to create a .htaccess file and add it to my dist because that is what the ISP console guide says to do.I am using Angular cli and the build command:ng build --aot --prod --base-href ./I have added this .htaccess file to my app folder - the same folder as my index.html file. This is the .htaccess code:RewriteEngine on RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^(.*) /index.html [NC,L]I tried various snippets from various different answers on SO, I tried the snippet on the angular.io guide, I tried changing the base-href. Nothing seems to work and I can't even be sure it's being added properly to my dist in the build. What can I do?
.htaccess redirects not working with Angular 4
"ALLOW-FROM uri" is not supported by all browsers. Ref:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
I'm trying to modify the x-frame-options in my .htaccess file. I would like for only one specific site to be allowed (apart from the sameorigin site) Although I am able to deny it for all, I have no clue on how to allow it for only one site, I have looked up the docs on MDN, but must have either overlooked something or I am not getting it correctly.Code that did work to block all:Header set X-Frame-Options DENYNone of the below examples did however work and resulted in a 500 external errorHeader set X-Frame-Options ALLOW-FROM URL Header set X-Frame-Options: ALLOW-FROM URL X-Frame-Options: ALLOW-FROM URLI have other code in the htaccess file and added all of the above to test on the first line of the file.Thanks for any help.
Modify headers x-frame-options in .htaccess
You should use Apache mod_proxy not mod_rewrite to run a Node.js app in Apache:<VirtualHost :80> ServerName example.com ProxyRequests off <Proxy *> Order deny,allow Allow from all </Proxy> <Location /myapp> ProxyPass http://localhost:61000/ ProxyPassReverse http://localhost:61000/ </Location> </VirtualHost>If you can't add a virtual host for your Node app you can try with htaccess and something like this:RewriteEngine On RewriteRule ^/myapp$ http://127.0.0.1:61000/ [P,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/myapp/(.*)$ http://127.0.0.1:61000/$1 [P,L]
I'm trying to run a small app I've wrote in nodejs on our server withforever. When I start my app like this:forever app.jsIn my folder/home/me/apps/myapp/and the app is listening on port 61000What should be the content of my .htaccess file undermydomain.me/myapp/?Current.htaccesscontent(not working):RewriteEngine On # Redirect a whole subdirectory: RewriteRule ^myapp/(.*) http://localhost:61000/$1 [P]
Redirecting with htaccess to nodejs app
You should simplify your rule. Go Daddy is annoying but this should work.RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ /$1.php [L]
My company is stuck with GoDaddy for now, and my .htaccess rewrite isn't working. This works fine on my localhost.The intent is to haveexample.com/aboutactually getexample.com/about.php, with the URL still just showingexample.com/about.Here's my .htaccess file:Options +FollowSymlinks -MultiViews -Indexes RewriteEngine on RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]I have read all the other posts about inconsistent .htaccess behavior with GoDaddy servers. I did have them confirm that mod_rewrite is enabled, and my PHP is 5.4.19. Hopefully someone has been through this already or can shed some light...
Simple .htaccess rewrite not working on GoDaddy
My tips are easily bypassed, but without be careful, we can be trapped.Only live view of the pageYou can replace or removescript tagwith javascript for hide this in live view of the page. But if you watch directly the network, you can see easily the javascript file/code.<div id="RemoveMe0"> <script type="text/javascript"> //This code it is hidden to live view. var my_var = 5 + 5; $('#RemoveMe0').remove(); //or document.getElementById("RemoveMe0").innerHTML = ""; </script> </div>For include javascript :<div id="RemoveMe1"> <script type="text/javascript" src="Javascript/MyJS.js"></script> <script> //Your include it is hidden to live view. $('#RemoveMe1').remove(); </script> </div>Only direct viewPut your files in an HTML file (myfile.js to myfile.html), like this on a direct view you can execute a javascript function.function Hello() { alert("Hello"); } Hello(); //<script>document.body.innerHTML = "";</script>Or if you don't want to rename your file, you can to use .htaccess file to modify file header.AddType text/html .jsOr minize/parse your JSYou can use tool like this :minize your js: This tool use eval function, and try to complicate your script.Javascript Obfuscator: Complicates the code for beginners, it's easy to by-pass.Google Closure JS Compiler: Optimize, compress, and minify your code.It is a natural tool for the production environment.Javascript to Asm.js
This question already has answers here:How can I block direct access to my JavaScript files?(6 answers)Closed10 years ago.This is my directory look like:index.htmldata.js.htaccessContent in index.html:<html> <body> <script src="data.js" /> </body> </html>My problem is:I don't want user to see mydata.jsby direct link likewww.sample.com/data.jsButdata.jsstill allow access fromindex.htmlI tried in .htaccess like:deny from allorRewriteEngine on RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] RewriteRule \.(gif|jpg|css|js|png)$ - [F]But it alway block access from index.html too.Thanks.
Block direct access to js, css file but allow access from index.html? [duplicate]
AllowOverride Alldoesn't belong in the htaccess file. It's used in the server config (httpd.conf) to set what an server config parameters an htaccess filecan override. So obviously, it would be wrong to be able to configure what parameters htaccess files can override from within htaccess files.Remove it from your htaccess file. You've already definedAllowOverride Allin your httpd.conf in the right places.
I have set up a server on my Mac (OSX 10.9) but it's returning a 500 error with the following message in the error log…[alert] [client ::1] /Users/user/Sites/mysite/.htaccess: AllowOverride not allowed hereHere's the code in my .htaccess fileOptions +FollowSymLinks -MultiViews AllowOverride All # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteMap lc int:toLower RewriteCond %{REQUEST_URI} [A-Z] RewriteRule (.*) ${lc:$1} [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^i/(.*)/(.*)-(.*)$ /items/?id=$1&range=$2&type=$3 [L,QSA,NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^c/(.*)$ /category/?menu=$1 [L,QSA,NC]And here's the relevant httpd.conf code (let me know if there's anything else that would help)DocumentRoot "/Users/user/Sites/mysite" <Directory /> Options FollowSymLinks AllowOverride All Order deny,allow Deny from all </Directory> <Directory "/Users/user/Sites/mysite"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all </Directory>Any ideas?
500 Error on apache server - "AllowOverride not allowed here"
If the form is submitted usingPOSTmethod (with attributemethod="post"in<form>), you can still execute your script only on POST requests, by adding this at the top:if ($_SERVER['REQUEST_METHOD'] != 'POST') { exit; }
Being a novice with PHP, I may not be taking the correct route with forms but this way works for me, up to a point. Below is an example of my setup/I have a form at www.foo.com/add.php, which needs an admin to be logged in to the session. The form inserts data into a database. Once it is submitted, the actions is set toaction="scripts/add.php"and then that is redirected using a PHP header function towww.foo.com/done.php.What I want to know is, can you deny access to the script file directly, e.g. if you go to the script file in a web browser it could enter an empty row into the database or possibly cause some other security issues?
Only allow access to PHP scripts from a form, not directly
Add this to your.htaccessin yourDocumentRoot. I am assuming that you are hosting only one domain on the server.RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} !^m\. RewriteRule ^$ http://anotherdomain.com [R,L]
I'd like to redirect only the base url to an external site.For instance, I wantexample.comredirected toanotherdomain.combut I don't wantexample.com/pathto be redirected.So far,example.com/pathredirects toanotherdomain.com/path. :(EDIT :First, thank you for the help! example.com now redirects to another.com without affecting the children paths of example.com.However, ideally,m.example.comwon't redirect toanother.com. So it's really justexample.comredirecting toanother.com.
Redirecting base url only using htaccess
If you request:http://myhost.comThe request needs to look like this in HTTP:GET / HTTP/1.0Host: myhost.comFor historical reasons, some browsers did append the slash because otherwise it translates toGET <nothing> HTTP/1.0Host: myhost.comWhich would be an illegal request.Note that:http://myhost.com/pageis legal, because it translates to:GET /page HTTP/1.0Host: myhost.com
I want my site to show up aswww.mysite.com, notwww.mysite.com/Does Apache add a trailing slash after a domain name by default, or does the browser append it? If I want to prevent this using an .htaccess, what would the url rewrite rule be?
Preventing trailing slash on domain name
Finally I find the problem. It's the AllowOverride option in httpd.conf which is located in /etc/httpd/conf/httpd.conf, "sudo find / -name httpd.conf -print" can easily find it. I changed any AllowOverride NONE->ALL where i can find in the file. It just worked,even without doing any change to .htaccess<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>This .htaccess works on my host in which wordpress is installed in its own directory.Thank you @adlawson @Will, without you, I couldn't find the problem.http://codex.wordpress.org/Using_Permalinksthis official guide is quite enough to use permalink even wordpress is installed in a sub directory.
I installed WordPress on EC2, located in/var/www/html/wordpress. I followed the WordPress guide to copy index.php and .htaccess to root which is/var/www/html, and modified index.php and setting in admin panel. It works pretty well if I stick to only default link, such as:http://www.cubcanfly.com/?p=5, however other permalink options fails, actually all of the permalink options.My.htaccessis# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>in/etc/httpd/conf/httpd.confLoadModule rewrite_module modules/mod_rewrite.sois NOT commented.Thanks in advance
Install WordPress in its own directory but permalink fails
Make sure your customized error page/404.htmlhas the content size greater than 512 bytes. Many browsers like IE, Chrome etc don't show your customized page if content length of your custom 404 page is less than 512.UPDATEBased on your comments here is what I think is happening.If you look at the access.log or http headers in Firebug/HTTP Watch etc of this blank page, you'd see a 404 return code. Once the web server starts processing the PHP page, it's already passed the point where it would handle 404 handling by itself since your php file is actuallyFOUND. Now since your php code is merely returning status 404without any contenttherefore a blank page gets displayed.Now since this is correct apache behavior and its up to you to create the contents for the 404 page. Something like this in your above php code will be fine I think:<?php header("HTTP/1.0 404 Not Found"); exit("<h1>Not Found</h1> The requested URL " . $_SERVER["REQUEST_URI"] . " was not found on this server. <hr>"); ?>
Why is this not working, as in the pre-set 404 page is not loaded:header("HTTP/1.0 404 Not Found"); exit;.htaccesshas theErrorDocument 404 /404.htmldirective set.Thank you.
PHP header 404 not working
if your apache instance allows you to override flags through.htaccessyou can put the following in your file:php_flag register_globals off
I have 2 scritpts on 2 different folders. One on them need the register globals to On and the other to Off.Is it possible to enable regsiter globals on one folder and disable it on another one ? (maybe with a .htaccess ?)regards
php register globals on/off through .htaccess
DownloadFiddlerand look at the raw response headers to see what the server is sending back for that particular request.FYI, Fiddler is a client side proxy that filters your browser requests through. Super informative when dealing with these kind of issues.-- UpdateUpon further investigation, it doesn't appear that your RewriteCond is actually doing what you think it is doing. According to theDocumentation, the RewriteCond directive is only used in conjunction with a RewriteRule.
I serve pre-compressed CSS and JS files on my site, and IE6-8 and FF is working perfectly with my .htaccess file.# Compressed files RewriteCond %{HTTP:Accept-Encoding} .*gzip.* AddEncoding x-gzip .gz AddType application/x-javascript .gz AddType text/css .gzI call the files with the .gz extension already [example]:<link rel="stylesheet" type="text/css" media="all" href="css/layout.css.gz" />So why is this breaks in google Chrome?Thanks.
pre-compressed gzip break on chrome, why?
Try this:RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Basically I have a folder on my webserver that I assign to new domains whenever I buy them that only has an index.html and an images folder. It is basically just has my logo and says the domain is under construction and coming soon.Normally when I want to force the www. prefix I use the following code:rewritecond %{HTTP_HOST} ^domain.com [nc] rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]This works fine however I need to explicitly write out the name of the domain. I deal with a lot of domains so I need code that will do this without knowing the domain name. I gave it a go but honestly got no one where close.
How can I use htaccess to force www. on multiple domains
RewriteCond %{HTTPS} on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}Yes, this will create a redirect loop. The logic is wrong. What this says is... if HTTPS is "on" then redirect to HTTPS. You should be checking if HTTPS is "off" (or "not on", ie.!on).(By removing the spaces between the arguments you likely created a rewrite loop, hence the 500 error. Spaces are delimiters in Apache config files.)Try something like the following instead:RewriteEngine On RewriteCond %{HTTPS} !on [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteRule ^ https://example.com%{REQUEST_URI} [R=302,L,NE]This handles both the HTTPS and www canonical redirects. You don't need the first rule. You don't need the<IfModule>container either.Change the302to301only when you are sure it's working OK.Make sure you've cleared your browser cache before testing. 301s get cached hard by the browser.UPDATE:If this still gives you the same error (a redirect loop) then it's possible that your SSL is managed by a front-end proxy, not your application server. If this is the case then you won't be able to use theHTTPSserver variable. See these related questions:http to https redirection through htaccess: incorrect redirection errorhtaccess rewrite - too many redirectsIt seems that in this case,ENV:HTTPS(an environment variable) needed to be used in place ofHTTPS(Apache server variable). Note, however, that this is non-standard / server specific, as it implies a front-end proxy is being used to manage the SSL.
I have this .htaccess file to redirecthttp://tohttps://I also didwww.to root domain redirection!www.to root domain works! howeverhttps://redirection doesn't! If I setRewriteCond %{HTTPS} ontoRewriteCond %{HTTPS} offorRewriteCond %{HTTPS} =!onI get a browser error:The example.com page isn’t workingmysite.com redirected you too many times.Try clearing your cookies.ERR_TOO_MANY_REDIRECTSOne edit I did gave me a 500 error but I reverted that back to how it was before! all I did was change:RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}toRewriteRule(.*) https://%{HTTP_HOST}%{REQUEST_URI}orRewriteRule (.*)https://%{HTTP_HOST}%{REQUEST_URI}Anyone have any Ideas on how to fix this issue?This is my entire.htaccessfile!<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond %{HTTPS} on [OR] RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteRule ^ https://antimalwareprogram.co%{REQUEST_URI} [R=301,L,NE] </IfModule>
.htaccess error - ERR_TOO_MANY_REDIRECTS
From the support:Does Cloudflare support wildcard DNS entries?Cloudflare Free, Pro and Business plan:We do not proxy wildcard records so these subdomains will be served directly without Cloudflare performance, security, or apps. The wildcard domain will have no cloud (orange or grey) on the Cloudflare DNS Settings page for that reason. If you are adding a*CNAME or A Record you need to make sure the record is grey clouded in order for the record to be created.To get Cloudflare protection on a wildcard subdomain (for example: www), you explicitly have to define that record in your Cloudflare DNS settings. First, log into your Cloudflare account and select the DNS icon. In this example, you would add "www" as its own CNAME record on your Cloudflare DNS Settings page and toggle the cloud to orange so the Cloudflare's proxy is enabled.Unless you are an Enterprise customer, you can't use a wildcard to redirect through Cloudflare.Make sure the cloud logo is grey to add a wildcard record:
Can somebody tell me how I can redirect all subdomains to the root domain in Cloudflare DNS?I have been looking for a day now without any luck.Ican'tuse.htaccessbecause all the subdomains doesn't resolve (They look just like a root domain that haven't propagated) and doesn't return anything, and I don't want to set up hundreds of DNS records for each possible subdomains.I would like to set up a wildcard dns entry to redirect or at least make all subdomains reachable, so I can either do the rest via the.htaccess, or through DNS.So how do I make the DNS entry for above requirements?Thanks.
Cloudflare DNS - How to redirect all subdomains to root domain?
Codeigniter by default will not add the current protocol to your base url, to fix your problem simply update:$config['base_url'] = 'www.mypage.si/';to$config['base_url'] = 'http://www.mypage.si/';if you want this to be a highly dynamic piece, this is what I currently have as my base url, and it never needs to be updated$config['base_url'] = "http".((isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS'])) ? "s" : "")."://".$_SERVER['HTTP_HOST']."/";NOTE:if you're using an IIS server, this may not produce the same results because theHTTPSelement in the$_SERVERglobal does not get filled the same way.
I'm having problem with Codeigniter which duplicates base_url. If i visit index page in controller all url are fine, but when i visit a page which is not index page in controller (cooling in my case) then i get strange duplicated urls like this onehttp://www.mypage.si/www.mypage.si/services/collingFor exampleThis is my services controllerclass Services extends CI_Controller { public function index() { $this->load->view('header'); $this->load->view('main'); $this->load->view('footer'); } public function cooling() { $this->load->view('header'); $this->load->view('cooling'); $this->load->view('footer'); } }my .htaccess fileRewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]Config.php$config['base_url'] = 'www.mypage.si/'; $config['index_page'] = '';This is my HTML<li><a href="<?php echo base_url('services/cooling'); ?>">cooling</a></li> <!-- results in: http://www.mypage.si/www.mypage.si/services/cooling--> <img src="assets/images/logo.png" /> <!-- results in: http://www.mypage.si/www.mypage.si/assets/images/logo.png --> <li><a href="<?php echo base_url()."services/cooling"; ?>">cooling</a></li> <!-- results in: http://www.mypage.si/www.mypage.si/services/cooling-->Thank you in advance!
Codeigniter duplicates base_url()
try this on your web.config and save it on the root<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <directoryBrowse enabled="false" /> <rewrite> <rules> <rule name="Hide Yii Index" stopProcessing="true"> <match url="." ignoreCase="false" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="index.php" appendQueryString="true" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
What is the.htaccessequivalent for IIS to enable pretty URLs in Yii2 on IIS. Indeed, I don't know what could I do withweb.confto allow those URLs.
IIS and Yii2 pretty URL
I found the solution for this issue.In my server the mode rewrite is already on. But some default values need to be change on/etc/apache2/apache2.conffile. Following are my changes,First, find<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>And changeAllowOverride NonetoAlland save.Then enable mode rewrite using the command(In this case already enabeled),$ sudo a2enmod rewriteThen restart the server,$ sudo /etc/init.d/apache2 restartRun the project. Works fine.
My CodeIgniter project is running successfully on my XAMPP system with the url,http://localhost/newsfeeds/users/allCategories/When I move this project to another system has LAMP server on Ubuntu 13.10. To run the same page I need the url,http://localhost/newsfeeds/index.php/users/allCategories/I need the index.php file otherwise it shows a page not fount error.My htaccess file is,RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]How can I run the same project without index.php on both WAMPP and XAMP server ?
htaccess is not working after moving from XAMPP to LAMP on ubuntu 13.10 (Enable htaccess in apache linux server)
Seethis answer:In your php.ini file, make sure you have something like this in it:extension=fileinfo.soor if you're on windows,php_fileinfo.dll.
I've used shared host for hosting my application and the version isphp5.3.27. I'm getting an error likeCall to undefined function finfo_open()So I've gone through some articles where I suggested by enabling fileinfo extension in .htaccess. For the first time I'm getting this error. Please help me to get the solution. The work would be more appreciated.
.htaccess enable php fileinfo extension
You want:ErrorDocument 404 /index.phpIn theErrorDocument docs:URLs can begin with a slash (/) for local web-paths (relative to the DocumentRoot), or be a full URL which the client can resolve. Alternatively, a message can be provided to be displayed by the browser. Examples:ErrorDocument 500 http://foo.example.com/cgi-bin/tester ErrorDocument 404 /cgi-bin/bad_urls.pl ErrorDocument 401 /subscription_info.html ErrorDocument 403 "Sorry can't allow you access today"So if it's not a FQDN or something that starts with a/, it is assumed that you want a customized message to be displayed.
I have a fileindex.php, and in the same level a.htaccesswith this code:ErrorDocument 404 index.phpWhen i generate a not found error is printed a page with the name of the file, so, in this case i only seeindex.phpas literal text. What i want is obviously a redirect to the homepage.Any idea about this problem?www\site -index.php -.htaccess
ErrorDocument 404 print file name
There is a difference between a rewrite and a redirect.Rewrite is an apache (and other servers) module that will follow a set of cond/rules to map a requested url to files on the server (ex: a bootstrap rewrites all urls to a single file, usually index.php. A mvc might map /model/controller/view uri to an index.php that calls the appropriate mvc files).A redirect actually changes the page you are on. Someone requests page A.php and that page says "what you are looking for is on B.php" and so your browser goes to B.php.A rewrite will preserve post parameters because the url doesn't change. A rewrite will just change the script being requested, but to the browser it looks like the page still exists at the requested url.A redirect will not preserve post parameters because the server will redirect you to another page completely.What it appears you are trying to do is a rewrite, not a redirect. You should have no problems getting the post parameters.To fix this, how are you checking in index.php that there are no post parameters? Are you sure the controller you are expecting is getting called?
.htacesssRewriteCond %{REQUEST_URI} ^/api/(.+)$ RewriteRule ^api/(.+)$ /index.php?api=%1 [QSA,L]example ajax url request: 'http://hostname.com/api/ext/list.php?query=de'I want to be able to redirect urls in this format to the following index.php?api={requested_filename}&param1=value1&param2=value2 ...because the whole site is processed through a bootstrap process in index.php which has a routing part loading configs, templates etc...When I try a jquery code for example, the POST data is lost after redirect.$.ajax({ url: '/api/contact.php', type: 'POST', data: { email: $("#contactEmail").val(), name: $("#contactName").val(), message: $("#contactMessage").val() // etc ... } });I've read that you cannot preserve data on a http redirect. But how do all the frameworks avoid that? I've coded in many, and every one is bootstraped through the index.php and there are rewrite rules in the .htaccess file for enabling pretty urls. So in Yii for example, I would call an url "api/uploads/latests.json" with some POST data and the controllers on the backend would receive that data. What am i missing here?note: I've tested the[P]mod_rewrite parameter, and i think that this server doesn't have mod_proxy enabled.
How to preserve POST data via ajax request after a .htaccess redirect?
+25You can useZend_Controller_Router_Routeand/orZend_Controller_Router_Route_Regexand define the routes$route = new Zend_Controller_Router_Route( ':key/:city_name', array( 'controller' => 'somecontroller', 'action' => 'pageAction' ), array('key' => '^\d+$') ); $router->addRoute('page', $route); // www.example.com/1/abc $route = new Zend_Controller_Router_Route( ':key/:city_name', array( 'controller' => 'somecontroller', 'action' => 'cityAction' ), array('key' => '^\d+\w+$') // www.example.com/1a/abc ); $router->addRoute('city', $route);
I have a set of urls like...www.example.com/page/1/name/abc www.example.com/city/la/name/abc www.example.com/page/1/name/abc/city/la www.example.com/page/1/And want to convert them as..www.example.com/1/abc www.example.com/la/abc www.example.com/1/abc/la www.example.com/1/Basically i want to hide keys from query string.How to do this? Any Help?EditI have different keys for every page and there are about 25 keys per page.
.htaccess Url Rewrite Remove Query-String Keys
In the htaccess file in your document root, add thesebeforeyour wordpress rules:RedirectMatch 301 ^/([^/]+)/([^/.]+)\.html$ /$1/$2/ RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/Of if you need to limit it by hosts, you can use mod_rewrite:RewriteCond %{HTTP_HOST} sitename.com [NC] RewriteRule ^([^/]+)/([^/.]+)\.html$ /$1/$2/ [R=301,L] RewriteCond %{HTTP_HOST} sitename.com [NC] RewriteRule ^([^/]+)/([^/]+)/([^/.]+)\.html$ /$1/$2/$3/ [R=301,L]
I've just changed permalinks in my wordpress site.And my old links were like that,http://www.sitename.com/category/postname.htmlNow new links arehttp://www.sitename.com/category/postname/I'm getting 404 error at old links, how can i redirect all .html pages to new non .html pages with .htaccess?
Redirecting old .html page to new without html extension page?
A 408 is aclient error:408 Request TimeoutThe client did not produce a request within the time that the server was prepared to wait.So you'll have totelnet <yourhost> 80and just sit and wait. Of course you can emulate this throughfsockopen()if you want to do it programmatically.Throwing the header from code might also work.
this may seem odd, but I actually need a PHP script that WILL time-out, i.e.: take so long to execute that Apache WILL time-out the script and fire a 408 error.The purpose for this, is to demo capturing the 408 with a custom 408 error page to report timeouts to a database.Perhaps there is a better way to do this that you may suggest?I don't think an infinite loop would work as Apache would 500 if I remember correctly.Edit -------It has been pointed out that a 408 is a client error, so in addition, what error would Apache fire if a script times-out?I'd like an actual example rather than a synthesizedheader()as this is to be pitched to a client and they would ideally like a real-world example.Thank you!
Purposfully timeout a PHP script
I use this and it works for me:RewriteEngine On RewriteBase / RewriteRule ^profile$ profile.php RewriteRule ^profile/([a-z0-9\-]+)$ profile.php?identity=$1 [NC,L,QSA]Now, how did you getprofile/abc? if you try to pass letters in the rule it wont work since you only specify numbers([0-9]+). If you want to pass letters you will need to use:RewriteRule ^profile/([a-z0-9\-]+)/?$ profile.php?identity=$1 [NC,L,QSA]
Hello I am writing a profile page script, in this script I check the value of an incoming $_GET variable and validate that it is an integer, I then validate this value against a $_SESSION value to confirm that they can only access their own accounts. The code looks like this:// validate $_GET field if(isset($_GET['identity']) && filter_var($_GET['identity'], FILTER_VALIDATE_INT, array('min_range' => 1))) { if(isset($_SESSION['user_identity']) && ((int)$_SESSION['user_identity'] === (int)$_GET['identity'])) { // if session exists and is === $_GET['identity'] // Proceed with codeThis works fine for instance if I try to pass '0','2-2','abc' or no value as the $_GET value the query correctly fails and redirects them to the home page.What I then tried to do was alter my .htaccess file to map the URLs to 'profile/1' just to tidy it up.RewriteRule ^profile$ profile.php RewriteRule ^profile/([0-9]+)$ profile.php?identity=$1 [NC,L]What I found now is that the page doesn't redirect any more using those invalid $_GET parameters above. It just tries to find 'profile/abc.Does anyone know why?
.htaccess and filtering $_GET
Perhaps you should try putting the same code into a php5.ini file instead of a .htaccess file. Godaddy servers are usually setup to accept configuration settings from php5.ini file.Make a text file with the filename as "php5.ini" and put the following in it:max_execution_time 8000 max_input_time 4000
I want to increase the maximum execution & input time for my PHP scripts. I added the following two lines to my .htaccess file located at the document root:php_value max_execution_time 8000 php_value max_input_time 4000It works perfectly well on my development server, but on the production server (GoDaddy) I'm getting a 500 internal server error. Why is it so?
Max execution time issue
it does not work because your last condition is not matching only the root but any uri that has / in it, which is basically everything. Try the following instead:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d [OR] RewriteCond %{REQUEST_URI} ^/$ RewriteRule ^(.*)$ /my/subfolder/$1 [L,QSA]Note that [NC] is not needed as you are not trying to match any alphabets, so "No Case" is not really needed.Hope it helps.
I would like mod_rewrite to redirect all requests to non existing files and folders, and all requests to the main folder ("root") to a subfolder. So i've set it up like this:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f [NC] RewriteCond %{REQUEST_FILENAME} !-d [NC,OR] RewriteCond %{REQUEST_URI} / [NC] RewriteRule ^(.*)$ /my/subfolder/$1 [L,QSA]Unfortunately, it does not work: if i request example.com/public/ it redirects to my processing script (so redirecting to my/subfolder/index.php?app=public ) although the folder "public" exists. Note that requesting domain.com/ correctly redirects to my/subfolder/index.phpWhy is that?
.htaccess redirect root to subfolder
You can't fetch insecure (http) resources from a secure (https) origin.It's called mixed-content and browsers block it for security reasons. (it may allow passive content like images, often with warnings)What you can do:explain to the web service the advantages of httpsproxy the answer of the web service through your sever
I am facing problem to call web service which is hosted over HTTP and I am calling web service from https domain.web service's htaccessRewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]i got following error in console when i am trying to calling web.angular.min.js:93 Mixed Content: The page at 'https://www.<my-domain.com>/#/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://<api url goes here>'. This request has been blocked; the content must be served over HTTPS.NoteWeb service is hosted in aws server which is http only. and my website is hosted to other hosting provider.
HTTP request has been blocked; the content must be served over HTTPS
You can enable fileinfo extension from cpanel 1 Go to SOFTWARE=>Select PHP Version=>fileinfo check box and enable fileinfo extension.
This error message appeared when I tried to upload an image on my shared hosting: "PHP Fileinfo extension must be installed/enabled to use Intervention Image". I then modified my php.ini settings using .htaccess.Now my .htaccess file looks like:<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] <IfModule mod_suphp.c> suPHP_ConfigPath /home/username/public_html/subfolder </IfModule> </IfModule>The subfolder specified in the .htaccess file is where my Laravel project is located, and it's where I want to serve my application.To enable PHPFileinfo, I wrote the following code in the php.ini file located in the project root:extension=fileinfo.so extension=pdo.so extension=pdo_mysql.soIt's not working on my shared hosting!How can I fix this?
How to enable extension=fileinfo.so in my shared hosting?
You are getting pretty URLs. This is a pretty url/book/read?t=booktitle&c=chaptertitleAn ugly URL isindex.php?r=book/read&t=booktitle&c=chaptertitleSo everything works as expected in yii2. Now you may want to make them prettier still, in this case you can add to your rule section something like'urlManager' => [ 'class' => 'yii\web\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ 'book/read/<t>/<c>' => 'book/read', ]This would generate a link that will look likebook/read/booktitle/chaptertitleChange it to suit your needs. No need to change anything in the controller, it will still receive the t and c parameters.
In Yii2, I cannot enable pretty url's.My config:'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, ],My .htaccess:RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.phpMy script:echo 'enablePrettyUrl: '; echo Yii::$app->urlManager->enablePrettyUrl ? 'true ' : 'false'; echo '<br>'; echo 'enableStrictParsing: '; echo Yii::$app->urlManager->enableStrictParsing ? 'true ' : 'false'; echo '<br>'; echo 'showScriptName: '; echo Yii::$app->urlManager->showScriptName ? 'true ' : 'false'; echo Url::to(['/book/read', 't' => 'booktitle', 'c'=>'chaptertitle']);The output from the script:enablePrettyUrl: true enableStrictParsing: false showScriptName: false /book/read?t=booktitle&c=chaptertitleClearly, I am not getting pretty Url's.Why not?We knowenablePrettyUrl=== trueI do not believe there is anything wrong with my .htaccess
yii2 urlManager enablePrettyUrl not working
You can use this rule in root .htaccess:RewriteEngine On RewriteBase / RewriteRule ^locations(/.*)?$ test.php [L,NC]
I have PHP project on localhost using XAMPP and also .htaccess file:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /locations/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /test.php [L] </IfModule>But this is not working and I am only getting Error 404. In httpd.conf file I have uncommented this line:# AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride AllI am using Windows 8.1. What can I do to make it work, please?
.htaccess file not working on localhost XAMPP
YourRewriteBaseis set to/myapp/but your index.php file is in/mayapp/public/is it not?As such, I think you'll find theRewriteBaseneeds to be/myapp/public/.
I have been spending hours on this issue and hope to find my way out. I have set up laravel correctly, created a project myappMy route.php file just containsRoute::get('/', function() { return View::make('hello'); }); Route::get('/users', function() { return 'Users!'; });When I runhttp://localhost/myapp/public/I get the laravel start page correctlyWhen I runhttp://localhost/myapp/public/usersI getThe requested URL /myapp/index.php was not found on this server.I don't know why its looking for index.php.When I runhttp://localhost/myapp/public/index.php/usersI get a page with text "Users". I should obtain this page when runninghttp://localhost/myapp/public/usersinstead.Below is my .htaccess<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On Rewritebase /myapp/ # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>Any ideas? Am running a Apache on Linux.
Laravel routes not working except for root
You need to use the%backreferences:RewriteCond %{QUERY_STRING} size=(\d+) RewriteCond ^ /%1 [L]The%1backreferences a previously captured group in a rewrite cond.
I have this rule:RewriteCond %{QUERY_STRING} size=(\d+)and want to capture(\d+)for later use inRewriteRuleorRewriteCond. Something like this:RewriteCond %{QUERY_STRING} size=(\d+) RewriteCond $1 <1024 ## that $1 refers to (\d+)How can I achieve that?
Capture a group in RewriteCond
Javascript running at client side, so your visitor can get any resource used by javascript. If you want to hide anything, you need to replace your javascript code by server-side generation.
I got a website, and the javascript file is loading a json file(using getJson) into options of one select element based on previous select option.But in the mean time, public can access that json file directly.I only want server can access this file and loads corresponding options in theselect element. But I don't want public can access that json file directly(avoid them downloading and such..)How do I do this? Via htaccess? or sth else? I tried 'FILES' rule in htaccess but the server cannot access the json file either.
I want to hide json file from public access. How do I do that?