Response
stringlengths
8
2k
Instruction
stringlengths
18
2k
Prompt
stringlengths
14
160
You can use this rule for removing multiple slashes anywhere in URLexcept query string:RewriteCond %{THE_REQUEST} \s[^?]*// RewriteRule ^.*$ /$0 [R=302,L,NE]
I currently have a website where guests are able to access each url with any number of slashes to separate folder names. For example, if a URL is supposed to be:http://example.com/one/two/three/fourThen users could access the same page via any of the following:http://example.com/one//two///three////four///// http://example.com/one/two////three/four///// http://example.com///one///////////two////three/four/ http://example.com///////////one///////////two/three/fourHowever, I want the above example urls to only redirect users to this URL:http://example.com/one/two/three/fourThis is my .htaccess file to attempt to stop the enormous slashes:RewriteCond %{ENV:REDIRECT_STATUS} !^$ RewriteRule .* - [L] RewriteRule ^(.*)/+$ /$1 [R=301,L,NC] RewriteCond %{REQUEST_URI} ^/+(.*)/+$ RewriteRule .* /%1 [R=301,L]The third line successfully stops trailing slashes on long URLs. The 4th and 5th lines are my attempt to stop trailing slashes right after the domain name, but that was unsuccessful.The reason why I ask this question is because I don't want google to catch me for duplicate content and with adsense active on the site, google will likely scan all the URLs that I access.Is there a RewriteCond/RewriteRule combo I can use to strip the middle slashes or is it more involved?
removing multiple groups of slashes everywhere in URL in .htaccess
You should test if new path points to an existing file:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [L,QSA]Otherwise you will get an infinite recursion (error 500).
I've recently added this little bit of code to my.htaccessfile:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.php [L,QSA]Ok, I understand what's happening here, I think. This little bit of code to remove PHP file extensions causes a loop if the document is not found. This loop causes a 500 server error instead of the (proper) 404. Unfortunately I have very little understanding of what these rewrites are actually doing, so I don't know how to rewrite it to only trigger this redirect if the document exists.I've done some reading and I'm not sure what Apache considers a "regular" file. I mean it works, but why wouldn't the first line be-finstead of!-f? Is-uthe only way to accomplish this?
htaccess rewrite causes 500 error instead of 404
+50Not much detail in your question, but let me try an angle that hasn't been taken yet (as far as I noticed).If you're asking why the.htaccess file works for this request:http://myserver.com/mypageOr eventhis request:http://localhost/mypageButnot this request:file://www/mypageIt's because the first two are actual HTTP requests, requiring the page to be 'served' by Apache. Apache (assuming a correct configuration for your situation) processes the .htaccess file while serving the request.That whole process is bypassed for the third 'request', because that's not a HTTP request, that's alocal filesystemrequest. In that case the web browser is loading a file much like a word processor. No web server is ever contacted, so the .htaccess file is meaningless.If that's what you mean bylocal, thento my knowledge there's no way to get a browser to process the .htaccess file for a local request.But in the future, there's a world of difference between requesting a flie for a local server, and loading a file from a local system.Again, this is only my take on one way your question could be interpreted, if indeed you're referring to requesting the file from a local web serve - check the configuration as many have suggested. (And check that you're running Apache too.)
Is there any way to run the.htaccessfile on the local server without being online?
Is there any other way to run .htaccess file on the local server?
Ok, here is the solution.In recents version of Apache (from 2.3.9), AllowOverride is set to NONE by default. Previous versions have AllowOverride set to ALL.Yii2 assumes that AllowOverride will be set to ALL.If you want to read the whole thread at Yii Forum, here is the linkhttp://www.yiiframework.com/forum/index.php/topic/53295-url-manager-for-seo-friendly-url-404-error-code/Thank you for your help and messages!
Well, PHP times.My client wants me to use Yii2 as the framework for his project.I got it up and running. No problem. I used the advanced template via composer.Set my web root to /frontend/web, etc.NOW, i want to use this url formatwebsite.com/messages/ or website.com/messages/tom... etc.Right now the way is setup showswebsite.com/index.php?r=messages/index...I found this documentation...https://github.com/yiisoft/yii2/blob/master/docs/guide/url.mdBut i can't seem to get it straight.Here are my steps...I configured my apache server to point to /usr/www/payroll/frontend/web/I added to my web folder a .htaccess file with this content.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.phpI also added the component 'urlManager' as in the directions. It seems to catch the request and modify it.'components'=>[ 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => 'false' ], ],For example if I type website.com you can see it adds /site/index to the url. (without the url component active it simply adds /index.php?site/index)So, obviously there's a modification perfomed to the url (via UrlManager) but I get 404 errorI am running out of ideas here. I am new to Php, Apache and Yii2. Any help, Greatly appreciated.Thanks
Yii2 Custom url management. Getting 400 error
That's because<?is the short opening tag for php.Try<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
OK firstly, I added this line to my .htaccess file so the php engine parses php code in .xml file:AddType application/x-httpd-php .php .php3 .phtml .html .xmlAfter that when I view an .xml file I get this PHP error:Parse error: parse error, unexpected T_STRING in /var/www/vhosts/mydomain.com/httpdocs/test.xml on line 1But line 1 is not even php infact this is line 1:<?xml version="1.0" encoding="utf-8"?>Can anyone tell me what the problem is?Thanks.
PHP error in .xml file?
I want to suggest something else that also works. Instead of writing a rule for every 'special' url, why not use one for all?I found it a whole lot easier to use what wordpress uses: every url is redirected to the index.All you have to do is, set up the index file, read in the directory that was loaded (perhaps using $_SERVER['URI_REQUEST']), and deal with it.add to .htaccess this:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>Thanks to that chunck you have a system somewhat unlimited at your disposal. If you ever feel like renaming you categrory url, or add another special case, it's already ready!
I have a PHP web app located onshared hosting. My goal is to modify .htaccess file from PHP code when the PHP page is running. I need that .htaccess to insert a couple of mod_rewrite lines into it.The problem is that on Windows+Apache I can dynamically modify .htaccess file but the same code on Linux reports a problem when I try to access this file in any way (copy or fopen):"failed to open stream: Permission denied"I have given .htaccess file 777 permissions - still no result. WHat prevents me from doing this? How can I develop a workaround?P.S. My initial goal was to be able to add a new RewriteRule into .htaccess that maps a newly added category_id with new category_name.If it wasn't shared hosting, I would use something like RewriteMap (in main Apache config) and would be able to access the map file.This is the first real limitation I've been unable to tackle with PHP+Apache, but I hope it's circuventable too.
Is PHP allowed to modify .htaccess file in current folder?
I suggest using a simple approach, essentially building on what you said, just anything with a dot in it, but working with the forward slashes too. To capture everything and not miss unusual URLs. So something like:^((?:https?:\/\/)?[^./]+(?:\.[^./]+)+(?:\/.*)?)$It reads as:optional http:// or https://non-dot-or-forward-slash charactersone or more sets of a dot followed by non-dot-or-forward-slash charactersoptional forward slash and anything after itCapturing the whole thing to the first grouping.It would match, for example:nic.uknic.uk/http://nic.ukhttp://nic.uk/https://example.com/test/?a=bcdVerifying they are valid URLs is another story! It would also match:index.phpIt would not match:directory/index.phpThe minimal match is basicallysomething.something, with no forward slash in it, unless it comes at least one character past the dot. So just be sure not to use that format for anything else.
I'm trying to write a regexp.some background info: I am try to see if the REQUEST_URI of my website's URL contains another URL. like these:http://mywebsite.com/google.com/search=xyzHowever, the url wont always contain the 'http' or the 'www'. so the pattern should also match strings like:http://mywebsite.com/yahoo.org/search=xyzhttp://mywebsite.com/www.yahoo.org/search=xyzhttp://mywebsite.com/msn.co.uk'http://mywebsite.com/http://msn.co.uk'there are a bunch of regexps out there to match urls but none I have found do an optional match on the http and www.i'm wondering if the pattern to match could be something like:^([a-z]).(com|ca|org|etc)(.)I thought maybe another option was to perhaps just match any string that had a dot (.) in it. (as the other REQUEST_URI's in my application typically won't contain dots)Does this make sense to anyone? I'd really appreciate some help with this its been blocking my project for weeks.Thanks you very much -Tim
regex to match a URL with optional 'www' and protocol
This .htaccess script works perfectly for me. Place it within the first set of folders inside your project directory. Same level as the index.php fileRewriteEngine on RewriteCond $1 !^(index\.php|public|\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1The error 500 can be checked on the apache error.log file using the following path /var/log/apache2/error.logCheck the last error listed and fix it.
I am starting a new project in codeigniter. While setting up work folder in localhost i put the following htaccess file in my project root folder for remove index.php from the urlRewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php?/$1now i am getting the error message as follows"Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request."my project path is localhost/scin the config.php file i put the following line$config['base_url']='http://localhost/sc';server error message is " Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration"I am using wamp server in windows platform please help me to solve this problemThank you
codeigniter localhost internal server error 500
You can usemod_rewriteto do that. Add the following in your.htaccessfile:Code:Options +FollowSymlinks RewriteEngine on RewriteCond %{REMOTE_ADDR} !=123.45.67.89 RewriteRule index.php$ /subscribe.php [R=301,L]Alternative solution:<?php $allow = array("123.456.789", "456.789.123", "789.123.456"); //allowed IPs if(!in_array($_SERVER['REMOTE_ADDR'], $allow) && !in_array($_SERVER["HTTP_X_FORWARDED_FOR"], $allow)) { header("Location: http://domain.tld/subscribe.php"); //redirect exit(); } ?>Hope this helps!
I'm not sure if this has been answered before but I tried looking for it. Anyways, I'm currently developing a website but I would like to make the actual site content only accessible from my IP address. I then want .htaccess to redirect all other IP address to a separate file on my server. That one file would be calledsubscribe.php.I've tried a couple things but nothing provided me with the result I wanted. I know my server allows.htaccessto be used since I've used it to change some other things such as preventing caches.
Allow access to all files from only 1 IP address and redirect all others to other file
The problem here lies with the fact that before Apache or WordPress come in to play, the browser needs to establish a connection with the server over HTTPS by connecting, performing an SSL handshake, exchanging (and verifying) certificates, and only after all that is done, will the browser issue the HTTP request that tells the server what resources it is looking for.Because of that, no .htaccess or WordPress plugin is going to be able to redirect the user without them establishing a secure session.Of course if you install a self-signed certificate, the user is going to be presented with a warning before any of this happens. If you by chance (which doesn't seem to be the cast) had been sending Strict Transport Security headers over https, then previous visitors' browsers may not even allow them to connect over HTTP.If you want to redirect HTTPS traffic to HTTP, unfortunately you are going to have to acquire a valid certificate and redirect using .htaccess or some PHP code as you are.If you're looking for certificates that are trusted by a majority of browsers without paying, you can get a free certificate fromLet's Encrypt.Bottom line, if you want to seamlessly redirect HTTPS traffic to HTTP without any warning messages, you need to install another SSL certificate from a trusted CA.
We have a WordPress site, and used to have an SSL certificate. The site used to be all HTTPS, and now we don't need the SSL anymore so we let it expire.We've already changed theSite AddressandWordPress Addressin the admin panel to behttp://example.com.We have several links out in the wild that link back to us withhttps://and if the user accesses the site withhttps://the site breaks or the user gets a warning message in their browser.Bottom line, we need to redirect allhttps://traffic tohttp://.I tried couple of plugins (no luck):https://wordpress.org/plugins/force-non-ssl/https://wordpress.org/plugins/wp-force-http/and even changed the.htaccessfile (still no luck)<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{SERVER_PORT} ^443$ RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>Not sure what else I need to do.
WordPress redirect all HTTPS to HTTP
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.phphttp://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/
Is there a way to hide the fact that I'm using PHP from my users? I wanted to do this for two reasons:1) So the links in the address bar look cleaner (like here on stackoverflow)2) To prevent potential hackers of knowing immediately what to look forIs point 2 even realistic or will a hacker know what I'm using anyway? I'm using nginx with php5-fpm.
Hide PHP from user
EDIT:tested and modified it, now it works for meI assume you want to add a default weight parameter if there is no weight at all:RewriteEngine on RewriteBase / RewriteCond %{QUERY_STRING} !weight= RewriteRule ^script.php script.php?weight=heavy [R,L,QSA]This is esentially the same what @coreyward answered, but a bit more specific. (R flag, to make the change visible, and the weight parameter does not have to be heavy.)Hope this helps!
I would like to use mod_rewrite to append a parameter to the end of a querystring. I understand that I can do this using the [QSA] flag.However, I would like the parameter appended ONLY if it does not already exist in the querystring. So, if the querystring was:http://www.mysite.com/script.php?colour=red&size=largeI would like the above URL to be re-directed tohttp://www.mysite.com/script.php?colour=red&size=large&weight=heavyWhereweight=heavyis appended to the end of the querystring only if this specific parameter was not there in the first place! If the specific parameter is already in the URL then no redirect is required.Can anybody please suggest code to put in my .htacess file that can do this?
Append a parameter to a querystring with mod_rewrite
<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^([0-9]{6})$ scriptname.php?no=$1 [L] </IfModule>To preserve the clean URLhttp://mywebsite.com/132483while serving scriptname.php use only [L]. Using [R=301] will redirect you to your scriptname.php?no=xxxYou may find this usefulhttp://www.addedbytes.com/download/mod_rewrite-cheat-sheet-v2/pdf/
Is it possible to use .htaccess to process all six digit URLs by sending them to a script, but handle every other invalid URL as an error 404?For example:http://mywebsite.com/132483would be sent to:http://mywebsite.com/scriptname.php?no=132483buthttp://mywebsite.com/132483a or http://mywebsite.com/asdfwould be handled as a 404 error.I presently have this working via a custom PHP 404 script but it's kind of kludgy. Seems to me that .htaccess might be a more elegant solution, but I haven't been able to figure out if it's even possible.
Is it possible to use .htaccess to send six digit number URLs to a script but handle all other invalid URLs as 404s?
In PHP you can get the data after the filename with the$_SERVER["PATH_INFO"]variable. This allows you to basically GET information without having to use GET variables, which means Google and co will think you're using static pages. This is basically an alternative tomod_rewritewhich is often enabled whilemod_rewriteis more often not enabled.This may be obvious to you, but it wasn't immediately to me, this doesn't work correctly on index pages unless you use the filename. For instance,http://example.com/test/my/get/paramswill not work, whilehttp://example.com/test/index.php/my/get/paramswill.
I don't get this:http://localhost/index.php/articles/edit/1/my-first-articleThis URL is mentioned as an example in theKohana framework documentation. I poked around in the files of my installation, and there is no .htaccess besides my own one that has nothing to do with that.So, how can it be that an index.php is called but then, as parameters, the stuff looks like added directories to the URL? That doesn't look "real".Or is this just how native PHP/Apache/HTTP stuff actually works? As I understand it, / is always telling "hey, a directory!". Makes really zero sense to me... how's that possible? Or do they have somewhere an .htaccess that I just can't see / find?
How can a URL like http://localhost/index.php/articles/edit/1/my-first-article work without an .htaccess?
This was answered on the Laravel forums.The problem was becauseAllowOverridewas set toNonein Apache. Changing that toAllsolved all the routing problems.Here is the example virtual host configuration from the post:<VirtualHost *:80> ServerAdmin[email protected]ServerName yoursite.com ServerAlias www.yoursite.com DocumentRoot "/var/www/yoursite.com/public" <Directory /var/www/yoursite.com/public> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost>
a simple 'test' route keeps returning a 404.Route::get('test', function() { return View::make('test'); });The route doesn't work whether it's localhost/test, or vhost.dev/test or even when using our sub.domain.com/test with the DNS pointing to that particular laptop.We were using XAMPP but switched to apache after learning that xampp was not suitable for a production environment. So I installed apache 2.4.7, php and the various sqlsrv mods on one of our win7 laptops. After moving to Apache, all routes have stopped working even with the same directory structure.I've also tried moving all files in /public into /htdocs and the rest of the app into a laravel folder in the root apache2.4 folder.I'm tested if mod_rewrite is enabled usingthis code on SO. This is the response so I suppose it is working?Apache/2.4.7 (Win32) PHP/5.4.24mod_rewrite availablehtaccess<IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>
Laravel routes returning 404 after move from xampp to apache 2.4.7. mod_rewrite or htacess or missing apache setting?
Since I'm guessingindex.phpis what gets served when you go to your document root, you want to explicitly check that/index.phpis what is beingrequested, and not part of the URI, which it will be once the URL-file mapping pipeline does its thing.RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php RewriteRule ^index\.php$ / [L,R=301]Then the www to non-www:RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
This question already has answers here:Generic htaccess redirect www to non-www(25 answers)Closed10 years ago.someone knows how can i redirect in the .htaccess this rules bellow ?http://www.domain.com/index.php to http://domain.comandhttp://www.domain.com to http://domain.commany tanks
Redirect index.php to root, and www to non www with rewrite_mod [duplicate]
Is your server using suPHP rather than mod_php or plain php-cgi?Try usingAddHandler x-httpd-php .html .htmorAddType application/x-httpd-php .html .htminstead.PostscriptShared Hosting services use UID based separation on individual accounts from each others. Most usesuPHP, but some usesuEXEC. They will use one of these. Both act as a su wrapper around php-cgi so you can't tell from the phpinfo()as its PHP scripting engine as this will reportServer APICGI/FastCGIin both cases. For CGI initiated scripts, phpinfo doesn't report on the Apache config. You need either to look at your hosting provider's FAQ or possibly try:<?php header( "Content-Type: text/plain"); echo system('grep -iR LoadModule /etc/httpd /etc/apache2');The hosting provider's support forums / FAQ might give specific configuration advice here. Have you tried them?
can't for the life of me work out why this isn't working - on a dreamhost server, I've created an htaccess file and addedAddHandler php5-cgi .html .htmto allow php in html files, as per the dreamhost docs. On an identical dreamhost package, I've done the same thing for another site and it worked perfectly, but in this case it just won't parse the php! Is there anything I could have missed here which could be causing the problem? The htaccess is in the web root and isn't being overridden by anything else.
htaccess rule to parse php in html files not working
RewriteEngine On RewriteRule ^(.*).css$ /includes/compressor.php?i=$1.css [L]These .htAccess command activate the RewriteEngine. This will let you analyse the request URL and execute the one you want into the server. The second line take all URL that end with .css and will take the file name to insert it as a parameter (like you wanted in your example).For example:http://localhost/styles/style1.csswill go tohttp://localhost/includes/compressor.php?i=style1.cssThe L flag will tell Apache to stop processing the rewrite rules for that request.
I have multiple css files in a directory (style0.css, style1.css etc..) How can I redirect a request to these css files with htaccess so that a php can process the requested css file. ex./styles/style0.css -> /includes/compressor.php?i=style0.css?
.htaccess redirect css to php
Rewritecond %{HTTP_HOST} !www.domain.com RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301]or maybeRewriteCond %{HTTP_HOST} !^www. RewriteRule ^/(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
Is there an easy way (preferably with htaccess and mod_rewrite) to force the browser to always access a site with the www. prefix (adding it automatically where necessary?)Thx.
Forcing the www prefix with PHP/htaccess/mod_rewrite
Is there any way you can re-structure your app so that those pages areoutsidethe document root? Much better answer...
Ok so i have a directory in my root folder called/pagesin which i keep all my pages that i include thru index.phpWhat I wonder is would could i somehow return a 404 error if someone requests it? i dont like snoopy people...
return 404 error on existing directory
You need to add commands like this to your .htaccess file:redirect permanent /some-article/http://www.example.com/some-article/Is this a server with mod_rewrite? In this case you could do a generic redirection for all paths:RewriteEngine On RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
I recently purchased a new domain for my WordPress site and I want to redirect anyone who visits using an old domain to the new one. I haven't moved servers, just added a new domain.For instance, if they went to either of these:http://www.example.net/some-article/ http://example.net/some-article/Then I'd like them to be redirected to the appropriate URL:http://www.example.com/some-article/ http://example.com/some-article/How would you do this simple .net -> .com redirect with a .htaccess file? Any rule should apply to all URLs under the .net domain.Thanks in advance.Edit:I already have the .htaccess file on the server:# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress AddHandler php5-script .php
Using .htaccess to redirect from one domain to another
You probably want something like theQSA("query string append") flag, which causes the remainder of the query string to be properly appended onto the end of the rewritten URL.For example:^test.php test.php?hidden=value [L,QSA]
I'm trying to rewrite the following URLtest.php?par1=foo&par2=barInto...newtest.php?hidden_par=blah&par1=foo&par2=barI have this rule, that does not work:RewriteRule ^test.php\??(.*?)$ newtest.php?hiden_par=blah&$1 [L]Could this be done using RewriteCond or something else? (say, could this be done ?), thanks in advance.
Mod Rewrite, pass parameters from URL1 to URL2
You need this entry in your.htaccessfile:Options -Indexes
I have a (Wordpress powered) website, and Google is indexing some of the sub-directories. How can I stop Apache from showing users the directory listing? I know I can edit .htaccess to password-protect a directory, but I would prefer a 403 / custom redirect if possible.
How do I stop visitors directly accessing the directories in my website?
First, you need to filter the permalink for your custom post type so that all published posts don't have the slug in their URLs:function stackoverflow_remove_cpt_slug( $post_link, $post ) { if ( 'landing' === $post->post_type && 'publish' === $post->post_status ) { $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); } return $post_link; } add_filter( 'post_type_link', 'stackoverflow_remove_cpt_slug', 10, 2 );At this point, trying to view the link would result in a 404 (Page Not Found) error. That's because WordPress only knows that Posts and Pages can have URLs likedomain.com/post-name/ordomain.com/page-name/. We need to teach it that our custom post type's posts can also have URLs likedomain.com/cpt-post-name/.function stackoverflow_add_cpt_post_names_to_main_query( $query ) { // Return if this is not the main query. if ( ! $query->is_main_query() ) { return; } // Return if this query doesn't match our very specific rewrite rule. if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) { return; } // Return if we're not querying based on the post name. if ( empty( $query->query['name'] ) ) { return; } // Add CPT to the list of post types WP will include when it queries based on the post name. $query->set( 'post_type', array( 'post', 'page', 'landing' ) ); } add_action( 'pre_get_posts', 'stackoverflow_add_cpt_post_names_to_main_query' );
I have a wordpress website which is using the custom template with custom post types like landing and services.Each post type have a specific slug in the url like this => (http://example.com/landing/landing-page-name)I want to change this url (http://example.com/landing/landing-page-name) to this url (http://example.com/landing-page-name).In fact I need to remove the [landing] phrase from the url. The important thing is that the [landing] is a custom post type in my posts table.I have tested following solutions:==> I have changed slug to '/' in rewrite property in register_post_type() --> It breaks the all of landings, posts and pages url (404)==> I added 'with_front' => false to the rewrite property --> nothing changed==> I tried to do this with RewriteRule in htaccess --> it did not work or give too many redirects errorI could not get a proper result.Did anyone solve this problem before?
how to remove custom post type from wordpress url?
The way I solved this is addingDirectoryIndex disabledto the.htaccess
So I'm running an express app in a shared hosting (FastComet) but if I want to get to '/' I get this messageCannot GET /index.html.varApparently it has something to do with the.htaccessfile
Express.js cannot GET /index.html.var
I know this is an old question, but I was having the same problem and I found a solution by adding aserver.phpfile to theroot directoryof the project with the following content:<?php $uri = urldecode( parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ); // This file allows us to emulate Apache's "mod_rewrite" functionality from the // built-in PHP web server. This provides a convenient way to test a Laravel // application without having installed a "real" web server software here. if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { return false; } require_once __DIR__.'/public/index.php';
I'm using hosting in linux and configured subdomain in my website in Apache2 server. I'm using laravel but I didn't use apache2 service by default. I'm using laravel artisan commands.php artisan serve --host 0.0.0.0It will listen to port 8000. So in order to access my website, I'm usedhttp://myipaddress:8000to access it.I tried to "chmod 755 or 777 public folder" but still didn't work. My .htaccess in laravel/public folder.htaccess<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]When I access my website with port 8000, below is my errors:PHP Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0 PHP Fatal error: Unknown: Failed opening required 'server.php' (include_path='.:/usr/share/php:/usr/share/php/PEAR') in Unknown on line 0
PHP Warning: No such file or directory in Unknown on line 0
You should define your apache configuration in another way. Your site should point to {folder}/basic/web and not to {folder}.Because you changed the requirements:For a cpanel setup you should:1) remove the silly basic folder, what is the point of it anyway? Just because Yii installs that way does not mean you have to keep it. So move everything 1 level up.2) Rename web to public_html make sure you rename it in some files too (config/bootstrap comes to mind).Yes you can do it with .htaccess but you should not have the files exposed to the internet, just your web folder should be exposed so I am not giving you that solution because it is not a good one.
Plenty of information around the net on how to hide the index.php from your Yii 2.0 application URL, however, what I'm trying to do here is to also remove the '/basic/web/' from the URL. /basic/web is the directory from which the application is running and the configuration that I have so far is the following. That goes into the config file:'urlManager' =>[ 'enablePrettyUrl' => true, 'showScriptName' => false, ],And this is my htaccess file that I have within the /web folder:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.phpSo far, so good, I can access something directly callingmysite.com/basic/web/controller/action. What do I need to do though to remove the /basic/web so that the URL becomes just simplemysite.com/controller/action?Any tips welcome, thanks!EDIT: I'm looking for a way without touching the apache configuration file as I don't have access to it.
Yii 2.0 hiding /basic/web from the URL along with the index.php
RewriteRule ^profile/([0-9]+)/([A-Za-z0-9-]+)/?$ index.php?p=profile&id=$1Should work for :www.domain.com/index.php?p=profile&id=20 to www.domain.com/profile/20/profile-friendly-name
I am trying to rewrite the urls of a site, i should mention that the way index.php works now is getting the p (page) parameter and including the appropriate file.So requesting a page is like this:www.domain.com/index.php?p=home www.domain.com/index.php?p=search www.domain.com/index.php?p=profile www.domain.com/index.php?p=contactI found how to create a rewrite rule for this:RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?p=$1so nowwww.domain.com/homewould give me the home pageBut i also need to have a friendly url for thiswww.domain.com/index.php?p=profile&id=20 to www.domain.com/profile/20/profile-friendly-name or better www.domain.com/profile/profile-friendly-name*The profile-friendly-name refers to a company nameRequirements:To have friendly urls for all pages e.g. /home, /contactTo have a particular friendly url for the profile page with the profile name in the urlMy questions:How can i add a profile-friendly-name to the url with the existing url format (index.php?p=profile&id=20)?Can i only have a unique name there (without the id), like my last example?If i manage to do that, will i have to change ALL the existing urls within the site (links, urls to images, to files) to the friendly format?I noticed that after applying the first RewriteRule some css stylesheets and js are not included. What is wrong?
Creating SEO friendly urls using htaccess
You're looking forErrorDocument.In your .htaccess specify the codes you want to handle, like:ErrorDocument 403 /error.php ErrorDocument 404 /error.php ErrorDocument 500 /error.phpAnd in error.php, handle the error codes like:<?php $code = $_SERVER['REDIRECT_STATUS']; $codes = array( 403 => 'Forbidden', 404 => 'Not Found', 500 => 'Internal Server Error' ); $source_url = 'http'.((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if (array_key_exists($code, $codes) && is_numeric($code)) { die("Error $code: {$codes[$code]}"); } else { die('Unknown error'); } ?>
How can I make .htaccess display errors from a PHP file? I mean when I search a non-existing file .htaccess should show me an error page from error.php, but error.php needs a parameter with the error code.NOTE:.htaccess should show the error directly on the current url without redirecting. Can I do this or it is impossible? Are there any other ways?
.htaccess show 404, 403, 500, error pages via PHP
Try setting:ExpiresActive On ExpiresByType text/javascript "access 1 month" ExpiresByType text/x-javascript "access 1 month" ExpiresByType application/javascript "access 1 month" ExpiresByType application/x-javascript "access 1 month" ExpiresByType application/json "access 1 month" // Thanks to David GossSee also:http://www.quickonlinetips.com/archives/2010/05/leverage-browser-caching-increase-website-speed/
I use below code in my htaccess for leverage browser cache,it has set expiry of 1month for javascript but when I test this google page speed insight the it asks for increase various js expiry and it shows set as 2 days as default why it happens?## EXPIRES CACHING ## <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg "access 7 days" ExpiresByType image/jpeg "access 7 days" ExpiresByType image/gif "access 7 days" ExpiresByType image/png "access 7 days" ExpiresByType text/css "access 7 days" ExpiresByType application/pdf "access 1 month" ExpiresByType text/x-javascript "access 1 month" ExpiresByType application/x-shockwave-flash "access 1 month" ExpiresByType image/x-icon "access 1 year" ExpiresDefault "access 2 days" </IfModule> ## EXPIRES CACHING ##
htaccess set expiry of js
This is not straight forward but here is a way it can be done in.htaccessitself:RewriteEngine On # set URI to /index.php/200 if query string is id=200 RewriteCond %{QUERY_STRING} (?:^|&)id=(200|1)(?:&|$) [NC] RewriteRule ^(index\.php)/?$ $1/%1 [NC] # set SECURED var to 1 if URI is /index.php/200 SetEnvIfNoCase Request_URI "^/index\.php/(200|1)" SECURED # enforce auth if SECURED=1 AuthType Basic AuthName "Login Required" AuthUserFile /full/path/to/passwords Require valid-user Order allow,deny Allow from all Deny from env=SECURED Satisfy any
I have a site with links like this:http://www.example.com/index.php?id=1http://www.example.com/index.php?id=3etc.I would like to have htaccess password protection for a specific ID, say 200.How can I do this?
Protect a url with HTTP authentication based on query string parameter
Its a tricky problem sincevar2=anythingcan really appear anywhere in query string.This code should work for you:Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{QUERY_STRING} ^(.+?&|)var2=[^&]*(?:&(.*)|)$ [NC] RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,L]
I would like to use mod_rewrite to remove a specifik query parameter from an URL.Example: 1) User enters URL:http://localhost/intra/page.htm?var1=123&var2=456&var3=7892) mod_rewrite removes "var2=456"3) New URL:http://localhost/intra/page.htm?var1=123&var3=789My problem is, that I only know the parameter name (var2), and not the value (456), and that I newer know the order of the parameters. It might be placed at the beginning as well as the end of the query string.I would appreciate any help, as I used a lot of time searching the web, without finding any working solution.
Use mod_rewrite to remove parameter
According to thePHP documentation, you can't use thedisable_functionssetting anywhere other than in aphp.inifile, so I'm very surprised this is working at all.If you need per-vhost or per-directory restrictions on functions, I would suggest using separate instances ofPHP-FPM, each of which can have its ownphp.ini. It also provides additional security benefits, such as complete sandboxing per daemon instance.
I'm trying to create a private clone of a popular website which gives the possibility to "write php code online" as a personal exercise.I write some code in a text areacode is executed some way server sideoutput is returnedI want the output to be exactly as it would be if served by an apache instance, with all the errors and warning my code generated.There's an existing framework which serves the site webpages (a front controller, an orm and so on) so I CANT USE DISABLE FUNCTIONS IN PHP INI. Or everything wouldn't be usable at all.I tried to save the input in a file and then run it with an exec like the following:exec("php -c mycustomphpinifile input.php 2>&1 > output.txt");But the errors outputted won't be the same as the apache ones.The final solution I'm trying to adopt is to use the php_value or php_admin_value within the httpd.conf or the .htaccess in order to disable a whole list (as you can imagine) of dangerous functions.However...php_value disable_functions "my,functions,comma,separated"doesn't work with such a big list as it seems. I have to disable something like 2k functions: is there any buffer size trouble with the php_value within the htaccess? Anyone can guess a solution to this problem?
Disable php functions within htaccess
Send a Method Not Allowed header along with some explanatory text (preferably something friendlier and more useful then my example below).Exit afterwards so you don't continue processing with the regular page.if ($_SERVER['REQUEST_METHOD'] === 'GET') { header('Method Not Allowed', true, 405); echo "GET method requests are not accepted for this resource"; exit; }You might want to consider white listing (and testing for the absence of methods you do accept) instead of black listing GET. (Since you might not want PUT, DELETE, etc either).
I want to disable HTTP GET method for some of my php pages in my website. Can I do it in php code?Lets suppose I have two pagesa.htmlandaction.php. Nowa.htmlis normal page can be accessed with any method and it submits the information toaction.php. But I want that information submitted toaction.phpcan only be submitted through post method.
Disable HTTP GET for some pages php
This should work (tested on my webserver: www.gopeter.de/test is restricted, www.gopeter.de/test/test.zip is allowed)AuthType Basic AuthName "Restricted Directory" AuthUserFile /path/to/directory/.htpasswd require valid-user <FilesMatch "\.(gz|pdf|zip|rar)$" > Order allow,deny Allow from all Satisfy any </FilesMatch>
Using htaccess I'm basically trying to forbid access to the page i.ehttp://example.com, but it will still allow people to download files if they have a direct link i.ehttp://example.com/hi.zip.I'm using the directory directive to display the basic download page. According toheremod_autoindex.cis used,so basically what I'm trying to do is:<Files mod_autoindex.c> AuthType Basic AuthName "Example" AuthUserFile "/home/.htpasswd" require valid-user </Files>Any advice/tips?
Htaccess access/download
This is all you need to get UTF-8 for both CSS and Javascript files:AddDefaultCharset utf-8 AddCharset utf-8 .css .js
I'm using:ForceType text/html;charset=utf-8in my .htaccess file, but it's causing all externally linked CSS to stop rendering on their respective pages.So something like this:<link rel="stylesheet" type="text/css" href="somestyles.css" media="all" />no longer works on the page using it.I've also been trying combinations of:AddCharset utf-8 .html AddCharset utf-8 .htm AddCharset utf-8 .css AddCharset utf-8 .js ForceType text/html;charset=utf-8 ForceType text/css;charset=utf-8but no luck so far. Does anyone know what's wrong?
ForceType text/html;charset=utf-8 in .htaccess is causing all externally linked CSS to stop rendering
To avoid recursion, you should check therequest lineinstead as the query string in%{QUERY_STRING}may already have been changed by another rule:RewriteCond %{THE_REQUEST} ^GET\ /\?(([^&\s]*&)*)tag=([^&\s]+)&?([^\s]*) RewriteRule ^(.*)$ /tag/%3?%1%4 [L,R=301]Then you can rewrite that requests back internally without conflicts:RewriteRule ^tag/(.*) index.php?tag=$1 [L]
How could I use a rewrite to change:/?tag=fooTo:/tag/fooI tried:RewriteCond %{QUERY_STRING} ^tag=(.+)$ RewriteRule ^(.*)$ http://www.example.com/tag/$1 [L]But it did not work.
.htaccess mod_rewrite: rewriting querystring to path
.htaccess files are configuration files used tooverrideoptions on a per directory level. These same options (and more) could be set from the main apache configuration (often in /usr/local/etc/apache*). If you own your server and have set up your Apache configuration properly it may actually be a gain todisable.htaccess for performance reasons.Not properly configuring permissions is usually a security risk. How you set them is up to you. Some people prefer having .htaccess enabled so they could keep application specific settings together.To answer your specific question about Joomla: the .htaccess file provided by default does little more than URL rewriting. This provides near-zero security benefit so not having a .htaccess file should not be a problem. It also adds some basic protection for some old third party modules. However you should be updating or removing them, not relying on .htaccessLastly it depends on what you mean by secure (as does almost any question relating to security).
I have a Joomla site www.siteA.com and another Joomla site www.siteA.com/siteB.I have a .htaccess -file at siteA, but not at siteB.Is it a security risk not to have a .htaccess -file at siteB?
Is it a security risk not to use a .htaccess file?
Ok, figured it out. Because I'm behind a load balancer, I had to replace:RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]WITH:RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]More info on why you need that header here:Load Balancers and HTTPS
Pulling my hair out. I need to force to HTTPS and getting too many redirects with the below in .htaccess file. Based on my research on Stack, this should work. Cleared cache, cookies, all that.<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] </IfModule>
Laravel force HTTPS with .htaccess too many redirects using Amazon ELB
You can use that in your root.htaccess:RewriteEngine on # redirect to https www RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(?:www\.)(domain\.com)$ [NC] RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L] RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC] RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L] # redirect to http subdomain RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^((?!www).+\.domain\.com)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L][EDIT]RewriteEngine on # redirect no-www to www only main domain, not with subdomain RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC] RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L] # redirect http to https all domain RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I’m looking to do this:Force the https for my main domain.http tohttps://www.http://wwwtohttps://www.But not for subdomainshttp://subdomain.domain.comtohttps://subdomain.domain.comCan some one help me i can't find this
htaccess redirect domain to https, subdomain to https and non-www to www
Wordpress templates are located inwp-content/themes/yourthemename/. Easy way to load a custom php file is to putserve.phpin that folder and to make that file apage templateby putting comment below at the beginning of the file:<?php /* Template Name: Serve */Now go toadmin->pages, create a new page and assign that page template from thetemplate dropdown. Open thehttp://mywordpresswebsite.com/serve/url in browser ( click onShow Pagein admin bar ) andserve.phpwill be loaded.
I have installed wordpress blog in my domain(Ex: http://mywordpresswebsite.com). Now i have a php file calledserve.phpin the root likehttp://mywordpresswebsite.com/serve.php.Now if i open the url in browser its saying page not found.then i have added RewriteRule^serve.php$ serve.php [L]in htaccess code, still its saying page not found.Please give me a solution for this as soon as possible, thanks in advance.
How to execute a custom php file with a wordpress website
You need to also enablemod_filterotherwise compression won't work.
I am using Apache 2.4 with PHP 5.5 on Windows Vista and trying to compress the files.Here is my.htaccessRewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)?$ index.php/$1 [L] # compress text, html, javascript, css, xml: AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascriptI havemod_deflate,mod_headerandmod_ext_filterenabled inhttpd.conf.But the sever is returning 500 error.Any Suggestions?
500 error when compressing files and using AddOutputFilterByType with .htaccess
Using mod_alias is even easier:Redirect 301 /old /newBut if you have rewrite rules in your htaccess file already, then you need to stick with using mod_rewrite:RewriteRule ^old/(.*)$ /new/$1 [L,R=301]
After migrating ta large static site to wordpress (as well as a reconstruction), I have a permalink structure that differs from the original directory structure, yet the new post slugs are the same as the original filenames. It's also worth mentioning that the permalink structure mimics the file extension of the old file path.For example:what was once (static directory)www.example.com/old/path/file.htmis now (wordpress permalink structure)www.example.com/new/path/file.htm (note: permalink structure mimics the .htm extension)My question: Is there a simple htaccess rewrite rule that can redirect visitors from /path/to/file/(file.htm) to /new/path/to/(file.htm), without having to create a redirect for each file?
htaccess 301 redirect entire directory
Assuming you have NO other sub domains butwww, you could have this simple rule on your.htaccessfile on the root of the domains in question if not the same root ofexample-new.co.uk:RewriteEngine On # anything that is not equal to www.example-new.co.uk RewriteCond %{HTTP_HOST} !^www\.example-new\.co\.uk$ # redirects to http://www.example-new.co.uk/anything RewriteRule ^/?(.*)$ http://www.example-new.co.uk/$1 [R=301,L]It will redirect anything not www.example-new.co.uk with the URL path to the new domain.So, if I access:http://example-new.co.uk/new-league <<< no wwwwI will be redirected to:http://www.example-new.co.uk/new-leagueAnd if I access:http://www.example-new.com/new-league <<< ends with .com http://www.example-old.co.uk/new-league <<< domain is different http://example-old.co.uk/new-league <<< domain is differentSo all the 3 above will also redirect to:http://www.example-new.co.uk/new-league
The company I do SEO for have changed their domain name.I have written 301 rewrites to redirect traffic to the new domain. So far, I have a rewrite for 3 changes, of which there are many. By the time I have finished doing them all, there will be around 30 rewrites, which seems a bit silly!Is there awildcardI can use to just make sure the following 3 arguments are met?Must always point to the www. version.Must always point to the co.uk version.Must ALWAYS change old URL to new.It would be something like this...(.*)example-old(.*)= www.example-new.co.ukand(.*)example-old(.*)/(.*)= www.example-new.co.uk/directoryThe below code sorts out problem 3, but it won't solve them all.If there is a short bit of code I can use, which uses wildcards, this will be perfect.Any help, much appreciated!# 301 --- http://example.co.uk => http://www.example-new.co.uk RewriteCond %{HTTP_HOST} ^example\.co\.uk$ RewriteRule ^$ http://www.example-new.co.uk/? [L,R=301] # 301 --- http://www.example.co.uk => http://www.example-new.co.uk RewriteCond %{HTTP_HOST} ^www\.example\.co\.uk$ RewriteRule ^$ http://www.example-new.co.uk/? [L,R=301] # 301 --- http://example.com => http://www.example-new.co.uk RewriteCond %{HTTP_HOST} ^example\.com$ RewriteRule ^$ http://www.example-new.co.uk/? [L,R=301] # 301 --- http://www.example.com => http://www.example-new.co.uk RewriteCond %{HTTP_HOST} ^www\.example\.com$ RewriteRule ^$ http://www.example-new.co.uk/? [L,R=301]
htaccess 301 Redirect Wildcard for New Base Domain Name
You don't have to specify them if you follow Apple's naming convention.From Apple'sdocumentation:If no icons are specified using a link element, the website root directory is searched for icons with the apple-touch-icon... or apple-touch-icon-precomposed... prefix. For example, if the appropriate icon size for the device is 57 x 57, the system searches for filenames in the following order:apple-touch-icon-57x57-precomposed.pngapple-touch-icon-57x57.pngapple-touch-icon-precomposed.pngapple-touch-icon.png
I'm in the process of building a new web application.I've got my favicon and apple icons all ready to go. I was wondering if I need to include them in the 'head' of my HTML file - or is routing them from the.htaccessfile acceptable?HTML code:<head> <link rel="shortcut icon" href="assets/ico/favicon.ico"> <!-- Standard iPhone --> <link rel="apple-touch-icon" sizes="57x57" href="touch-icon-iphone-114.png" /> <!-- Retina iPhone --> <link rel="apple-touch-icon" sizes="114x114" href="touch-icon-iphone-114.png" /> <!-- Standard iPad --> <link rel="apple-touch-icon" sizes="72x72" href="touch-icon-ipad-144.png" /> <!-- Retina iPad --> <link rel="apple-touch-icon" sizes="144x144" href="touch-icon-ipad-144.png" /> </head>or just put them in htaccess?# Rewrite for Favicons RewriteRule ^favicon\.ico$ assets/ico/favicon.ico [L] RewriteRule ^apple-touch-icon\.png$ assets/ico/apple-touch-icon.png [L] RewriteRule ^apple-touch-icon-57x57\.png$ assets/ico/apple-touch-114-icon.png [L] RewriteRule ^apple-touch-icon-114x114\.png$ assets/ico/apple-touch-icon-114.png [L] RewriteRule ^apple-touch-icon-72x72\.png$ assets/ico/apple-touch-icon-144.png [L] RewriteRule ^apple-touch-icon-144x144\.png$ assets/ico/apple-touch-icon-144.png [L]Question:Is there any negative to just putting them in my.htaccessfile and removing them from my HTML?
Apple touch icon in html head or htaccess file
Your RewriteCond should be like this:RewriteCond %{REQUEST_URI} ^/(admin|js|css)/ [NC]Additionally you must useLandQSAflags in all the RewriteRule lines like this:# skip these paths for redirection RewriteCond %{REQUEST_URI} ^/(admin|js|css)/ [NC] RewriteRule ^ - [L] RewriteRule ([^/]+)/([^/]+)/([^/]+)/?$ index.php?grandparent=$1&parent=$2&page=$3 [L,QSA] RewriteRule ([^/]+)/([^/]+)/?$ index.php?&parent=$1&page=$2 [L,QSA] RewriteRule ([^/]+)/?$ index.php?page=$1 [L,QSA]
So I have the following rewrite rules:RewriteRule ([^/]*)/([^/]*)/([^/]*)$ /index.php?grandparent=$1&parent=$2&page=$3 RewriteRule ([^/]*)/([^/]*)$ /index.php?&parent=$1&page=$2 RewriteRule ([^/]*)$ /index.php?page=$1But I need this to not pass to the index page for some sub-domains, so I have the following rewrite conditions before this:RewriteCond %{REQUEST_URI} !^/css/.*$ RewriteCond %{REQUEST_URI} !^/js/.*$ RewriteCond %{REQUEST_URI} !^/admin/.*$So that the rules will not apply when looking for any file in those directories (including files that may be in sub-directories of those directories). Yet they still keep getting rewritten toindex.php.How can I make exceptions for these directories?
.htaccess rewrite folder exception
Using mod_rewrite, stick this in an appropriate place in your .htaccess fileRewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} !^/fbthumbnails/ RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]Change theRtoR=301if you want a permanent redirect.
I don't know why I can't find this or do this but basically all I want to do is redirect any page on my server to https:// unless it is in the folder /fbthumbnails/ because facebook doesn't allow thumbnails to be https://.
htaccess redirect all to https to http except for one folder
My server is on LAMP configuration with PHP 5.3 and fast CGI.You can not set PHP ini directives with the.htaccessmethod with FCGI/CGI. You need to apply the changes within the php.ini or better theuser ini filesDocsinstead.Place a file called.user.iniinto the document root and add theauto_prepend_fileDocsdirective in there:auto_prepend_file = /home/user/domain.com/init.phpThis should do the job for you.
I have a file calledinit.phpwhich I want to get automatically included in each and every HTTP request coming to my server. My server is on LAMP configuration with PHP 5.3 and fast CGI. Any method to achieve this is welcome.What I have already tried:I have already tried theauto_prepend_filemethod with.htaccessfile but no success.I have done the following..htaccessFile:php_value auto_prepend_file /home/user/domain.com/init.phpinit.phpfile:<?php echo "statement 2"; ?>index.phpfile:statement 1So, now if I visithttp://domain.com/I find only statement 1 getting printed. statement 2 is not getting printed.Kindly let me know how to correct this or if there is any other way to achieve this.
How to include a php script in all HTTP requests coming to the server
Yes, you can use mod_rewrite to rewrite all urls. The following will rewrite all non-existing files and folders to requested filename .php:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.php [L]Visiting/blogand it's not an existing directory will cause this rule to rewrite it as/blog.php.
I have a static website with files like index.php, blog.php, contact.php etcHow can I get my website addresses to work so that www.site.com/blog takes you to blog.php?I think htaccess could do this for me, but am a php noob!The only alternative I currently use is to create individual folders called 'blog, contact etc' which contains another index.php file inside itthanks
How to get to php pages without using .php in URL
Your code looks pretty different from the code foundhere. What about trying:<Files ~ "(.js|.css)"> Order allow,deny Deny from all </Files>If you are using version Apache 2.4 or higher<Files ~ "(.js|.css)"> Require all denied </Files>
If the remote user knows the exact location of the file, he will still be able to access the file from a browser. How can someone find out about the location of the private file? well this doesn’t really matter too much, but he might see paths, or files, shown in a warning messages, or the files might be browsable (there is no hiding of the files in the directory indexes). So if there are ‘special files’ that you want to not be served in any case to remote users then you will have to deny access to them. But the question is HOW?Inside my .htaccess file in my webroot folder:<FilesMatch "\.(js|css)$"> Order deny,allow Allow from all </FilesMatch>But that doesn't seems to work.. :-(I'm using Apache 2.2
How to restrict/forbid access to specific file types such as .js .css inside a .htaccess file?
Turns out what i was doing was correct just took a while for it to start working. Then when it still did not work in Firefox had to clear offline memory and started working too.
Closed. This question needsdetails or clarity. It is not currently accepting answers.Want to improve this question?Add details and clarify the problem byediting this post.Closed7 years ago.Improve this questionI have a download vCard (.vcf) link on a site. It works locally but not online. Just opens file in browser without downloading. I would rather not have to zip it.Read around and found I need to put this:AddType text/x-vcard .vcfin a .htaccess file. but it's still not working. Am I missing something?The site is hosted with godaddy. One old thread I read somewhere had a guy who made it work but no more info other than the .htaccess bit.
vCard .vcf file download browser support - godaddy [closed]
RewriteEngine on RewriteCond %{HTTP_REFERER} !http://your-domain\.com/.* [NC] RewriteRule ^.*js$ - [F]This will return 403 code (forbidden) when referer is outside your domain for all JavaScript files.NOTE: But this solution will only make access to the file harder. If someone will want to see the file, he will do that eventually. Because you can't fully block the js files, if the browser can read it, the user also will. Example: you only can open dev tools and you will see the source. Or if someone will figure out that the block is by referrer he can create link to file or use other way to add the header to the request.
Let's say I have a JavaScript file... using .htaccess is there a way I can make it so a user can NOT look inside the JavaScript file?
Block access to JavaScript file
Your configuration looks perfectly fine. You should just change LogLevel from debug to warn (or whatever your favorite level is).
Receiving error: [debug] mod_headers.c(663): headers: ap_headers_output_filter()after I included this within the htaccess file:# 6 DAYS <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=518400, public" </FilesMatch> # 2 DAYS <FilesMatch "\.(xml|txt)$"> Header set Cache-Control "max-age=172800, public, must-revalidate" </FilesMatch> # 2 HOURS <FilesMatch "\.(html|htm)$"> Header set Cache-Control "max-age=7200, must-revalidate" </FilesMatch>Any help is appreciated as to what I could do to fix this?
Error headers: ap_headers_output_filter() after putting cache header in htaccess file
This should work for both:RewriteEngine on RewriteRule ^([^/]+)/([^/]+).*$ $1.php?id=$2 [L]Explanation:^ - beginning of the string ([^/]) - first group that doesn't contain / will match both 'profile' and 'store' will also be referenced by $1 later / - first slash separator ([^/]) - second group, id in your case will be referenced by $2 .* - any ending of the request uri $ - end of request stringYou can also make it more precise so only the two request are rewritten and only digits are accepted as id:RewriteRule ^((profile|store))/(\d+).*$ $1.php?id=$2 [L]
How do I convert something likeme.com/profile/24443/quincy-jonestome.com/profile.php?id=24443or something likeme.com/store/24111/robert-adamstome.com/store.php?id=24111with mod_rewrite?Can I make the reverse conversion as well with mod_rewrite, or would I have to parse it through PHP?
using apache's mod_rewrite to parse SEO friendly URL's
I decided to ask Intercom themselves, through their support channel, for an answer, and I was given the following response:This isn't actually something we do anything too special with, it is all to do with the configuration of the web server, both on our side and the side of the client.This stackoverflow goes into more details on this, but keep in mind that whilst it is a ruby StackOverflow - it focuses on the web server set up, in this case nginx - but it could be any web server software.How to preserve request url with nginx proxy_passThis then allows your service to receive the requests, but also have access to the original server address - we then ask our customers to provide the custom domain they are using within their Article Setting to help us translate the server address to the correct help center.I do hope this helps, if you do have any follow up questions I'm happy to try and help, but as you mentioned this does fall out of the scope of our team so the help I can provide may be limited.Quite happy with the response, as they went above and beyond for me. Basically, the path I was on was the correct one. I decided to leave the question to help others. I also found the following related questions:How do I enable custom domains for my users?How to give cname forward support to saas softwareCustom domain feature for saas product customersGood luck to those who find this.
I want to implement the same functionalityIntercomprovides to their clients; they allow the implementation ofCustom Domains for Articles. I'm not quite sure how they go about their method of implementation, or what they're doing behind the scenes, exactly.Take the following scenario; a client (company NorthWind), has a subdomain on my company's website (northwind.example.com).The following is to occur:If a user typesnorthwind.example.com, they go tonorthwind.example.comandnorthwind.example.comappears in the url bar.If a user typesexample.northwind.com, they go tonorthwind.example.comandexample.northwind.comappears in the url bar.The difference between the way Intercom implements it and the way I wish to implement it is that I'm using asubdomain, not a directory, as seen in Intercom's help article linked above.Considering my website runs on Nginx, NodeJS, and MongoDB, here's what I came up with so far:Client registers a CName record on their domain provider to point to their page on my website.Client provides the CName record they used to my website (register it through a form).I save a record in MongoDB for the company and their custom domain.I register, or re-register, the reverse proxies of my website, usingredbirdto allow the redirection to go through.I've already looked intoRedirect Web Page to Another Site Without Changing URLandDoes a Cname Change the URL that the Browser Displays.Am I on the right path, or is there a better method?
How to allow clients to set up custom domains for their own pages on a service website?
You can use CURL..GET REQUEST$url = 'http://example.com/api/products'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response_json = curl_exec($ch); curl_close($ch); $response=json_decode($response_json, true);POST REQUEST$postdata = array( 'name' => 'Arfan' ); $url = "https://example.com/api/user/create"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); $json_response = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl);You can also usefile_get_contentto get API data.$json = file_get_contents("$url")
I want to check all of the requested urls and if the url contains "video" folder in it, redirect it to an API file. then the API gives me a json files which only contains "respond:true" or "respond:false". In case of having respond:true in the json file the url must be showed and if the json file contains respond:false a predefined simple 403 page must be showed to the user.I know that the fist part is possible with a simple code in .htaccess file like this:RewriteRule ^your/special/folder/ /specified/url [R,L]But I don't know how to do the second part. I mean how to get the result of API, which is in form of a json file and check it.
how to call an api via php and get a json file from it
The best approach is to move the sitemap.xml file to thepublicdirectory. You do not even have to worry about the routing as well.Then it will automatically be accessible ashttp://example.com/sitemap.xml
I havesitemap.xmlin the root directory ofhttp://example.comWhen I try to accesshttp://example.com/sitemap.xml. It obviously throws route not found error.So to try this changed.htaccessto look like:Options +SymLinksIfOwnerMatch RewriteEngine On RewriteCond %{REQUEST_URI} !^/sitemap.xml RewriteRule ^ index.php [L]Laravel version in use: 5.1.But, no luck. How can I just make use and render manually generated XML file rather than serving from route? I am not looking for complex XML parsing theory here. Just trying a hook to escape from the specific routing.
How to ignore sitemap url from Laravel routing?
You can detectmod_phpin .htaccess and ensure that these directives are only attempted when supported. In .htaccess:<IfModule mod_php5.c> php_value upload_max_filesize 100M php_flag ... </IfModule>Note: Depending on your setup you might need to changemod_php5.ctomod_php4.cormod_php.c.In addition, you can manually stop the redundant php.ini file from being publicly accessible when in php mode using the following in .htaccess:<Files ~ "\.ini"> Order allow,deny Deny from all </Files>Hope this saves you some time!
I usephp_valueandphp_flagrules in.htaccesssuch as:php_value upload_max_filesize 100MBut this causes an error when the server is running in CGI mode instead of Apache mode, and instead I have to use php.ini rules such as:upload_max_filesize = 100MMy code libraries needs to work for either mode, without manual changes for each server.It took me a while to find a solution to allow both methods to be in place, and as it was hard to find I thought I'd post my solution here.
Detect support for php_value / php_flag in .htaccess to suppress errors - PHP CGI mode - mod_php
I figured it out and I'm posting if somebody will need it.Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteRule ^wp-content/uploads/(.*) http://their-domain.com.com/wp-content/uploads/$1 [R=301,NC,L]
I'm working on the WordPress site. It's currently on client's server and I want to move to my dev server.The wp-content/uploads folder is more than 13GB and it's a big problem during and after migration.What I need to achieve is to set up a redirect rules in .htaccess file that will fetch remote files from uploads folder on their server.For example if I call:my-domain.com/wp-content/uploads/2015/02/image.jpgit should display:their-domain.com/wp-content/uploads/2015/02/image.jpgso I wouldn't have to migrate all file in order to make the site work.Also is there a way in that case to write exception for foldermy-domain.com/wp-content/uploads/2015/04/so every image that I upload now will be fetched from my domain?Thanks for the help
Wordpress remote uploads folder
This is quite an old question but maybe this answer is relevant for you Google users out there:Did you change the View/Layouts/default.ctp?This is what happens with this warning:The warning is set in a div in View/Pages/home.ctpIn home.ctp only sets the warning when the file app/webroot/css/cake.generic.css existsIn the standard default.ctp layout, the stylesheet /css/cake.generic.css is loadedIn cake.generic.css the div with the warning is.... hidden!!!So what happens when the default home page loads: it tries to load the cake.generic.css style sheet, which succeeds when mod_rewrite is configured correctly. So then the warning is hidden. If it fails to load the style sheet, the warning will stay visible.This warning pops up, in short, when either there is a problem with mod_rewrite and htaccess,or you changed the layout so that the cake.generic.css is no longer loaded...First check if you even try to load the stylesheet. Does it show up in your F12 console?
I think somehow most of us had a trouble with .htaccess I d'like to know if someone can help me. Opensuse 12.3 : Code:Linux linux-hyo0.site 3.7.10-1.16-desktop #1 SMP PREEMPT Fri May 31 20:21:23 UTC 2013 (97c14ba) x86_64 x86_64 x86_64 GNU/LinuxI d'like to install Cakephp on my machine but I have an error on my webpage saying that " Code:URL rewriting is not properly configured on your server."my /etc/sysconfig/apache2 file as this : Code:APACHE_MODULES="authz_host actions alias auth_basic authz_groupfile authn_file authz_user autoindex cgi dir include log_config mime negotiation setenvif status userdir asis imagemap php5 reqtimeout authz_default rewrite"and the /etc/apache2/sysconfig.d/loadmodule.conf as this line at the end Code:LoadModule rewrite_module /usr/lib64/apache2/mod_rewrite.soI did also change my file etc/apache2/defaul-server.conf<Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory "/srv/www/htdocs"> Options Indexes FollowSymLinks MultiViews AllowOverride ALL Order Allow,Deny Allow from all </Directory>Any help?on app/webroot<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>and on app/<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L] </IfModule>
Cakephp 2.x URL rewriting is not properly configured on your server
Ok I can't take the full credit for this, as it was by a user on another forum where i'd posted, but thought i'd share in case it helps someone on here.RewriteCond %{REQUEST_URI} ^/news/latestnews/(.*)$ RewriteRule ^news/latestnews/(.*)(201[0-9])(.*)$ /news/$2/$1$2$3 [R=301,L]This will actually deal with all years from 2010.
A site i'm working on had news articles sitting within a latest news directory./news/latestnews/some-article-2012.htmlThese have now been moved in to different directories depending on the year of the news article. So 2013 are now within:/news/2013/some-article-2013.htmland 2012 are in:/news/2012/some-article-2012.htmlI can easily latestnews to one of the directories using:RewriteRule ^news/latestnews/(.*)$ /news/2011/$1 [R=301,L]But i need to redirect to the specific year directory. All news articles contain the year in name. So some-article-2012 or some-article-2013.Any help on adjusting my rule to also check the year.Thanks=========EDIT=======I've managed to add some RewriteCond to redirect to the correct directory but having trouble appending the requested file name.So using this ruleRewriteCond %{REQUEST_URI} ^/news/latestnews/(.*)$ RewriteCond %$1 ^(.*)2012(.*)$ RewriteRule ^(.*)$ /news/2012 [R=301,L]This url/news/latestnews/some-article-2012.htmlgets redirect to/news/2012but the "some-article-2012.html" is missing from the url.I've tried adding $1 to the end of the rewriterule so you have:RewriteRule ^(.*)$ /news/2012$1 [R=301,L]But the the full old url gets appended so you have:/news/2012/news/latestnews/some-article-2012.html
htaccess redirect if url contains a specific word
Your first example is failing because of the spaces; a better regex would be something likeRewriteCond ^/(it|de|fr)/ RewriteRule 'myhomepageurl'Either way, you should readWhen Not To Use Rewriteand use one of the simpler forms suggested there, e.g.RedirectMatch /(it|de|fr)/ /myhomepageurl
I am looking for a solution where i can define the muliple match statement whitin the single RewriteCond statement,The scenario is i want to redirect to home page if any of this string comes in the url:/it/, /de/, /fr/I tried to wrote it like this:This is throwingSERVER ERROR:RewriteCond ^(/it/ | /de/ | /fr/ ) RewriteRule 'myhomepageurl'I also tried this way too:RewriteCond /it/ [OR] RewriteCond /de/ [OR] RewriteCond /fr/ [OR] RewriteRule 'myhomepageurl'This was giving unexpected results page loding infinite and admin was blocked. So i finaly took this way:RewriteCond /it/ RewriteRule 'myhomepageurl' RewriteCond /de/ RewriteRule 'myhomepageurl' RewriteCond /fr/ RewriteRule 'myhomepageurl'I am just curious about the single statement that can do this in single shot.Thanks
htaccess use OR condition in RewriteCond
something like:RewriteEngine on RewriteCond %{HTTP_USER_AGENT} "MSIE [6-8]" [NC] RewriteRule ^(.*)$ http://mysite.com/ie [R=301,L]
How can I redirect users for IE versions 6-8 with htaccess to a certain directory (mysite.com/ie)?Note: I am using Wordpress.
Redirect IE 6, 7 and 8 users with htaccess
You just follow this sample code for .htaccess files...<Files ~ "^\.(htaccess|htpasswd)$"> deny from all </Files> <IfModule mod_rewrite.c> RewriteEngine On ErrorDocument 404 /404.php </IfModule> Options -Indexes RewriteEngine on RewriteCond %{HTTP_HOST} ^(yourwebsite.com)(:80)? [NC] RewriteRule ^(.*) http://www.website.com/$1 [R=301,L] DirectoryIndex index.php order deny,allow Header unset ETag FileETag None <FilesMatch "\.(jpg|png|gif|js|css|ico|swf)$"> Header set cache-Control: "max-age=572800, must-revalidate" </FilesMatch>This would more help for us.....other wise it will help you...<Files ~ "\.html$"> Order allow,deny Deny from all Satisfy All </Files> <Files ~ "\.css$"> Order allow,deny Deny from all Satisfy All </Files>Else its will working well.. i `ll checked this code in my website.Options +FollowSymlinks # Prevent Directoy listing Options -Indexes # Prevent Direct Access to files # SEO URL Settings RewriteEngine On # If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ RewriteBase / RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css) RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]Thank u....for giving opportunity post for you...
I'm trying to hide my .htaccess file so everyone can't just read it out in their browser.My .htaccess file is located here:http://businessgame.be/.htaccessas you can see you can still just read it out.I tried adding the following:# secure htaccess file <Files .htaccess> order allow,deny deny from all </Files>and also<FilesMatch "^\.ht"> Order allow,deny Deny from all </FilesMatch>But none of it seems to work. This is really weird. Am I doing anything wrong?
Trying to hide .htaccess file
Just remove the first forward slash:RewriteRule ^fr/(.*)$ /$1 [L,R=301,QSA].Try this out athttp://htaccess.madewithlove.be/.
After more than one hour of searching, I still can't figure out how to redirect a link fromhttp://site/fr/othertohttp://site/other.I am using this code:RewriteEngine On RewriteRule ^/fr/(.*)$ /$1 [L,R=301,QSA]
In .htaccess remove word from URL
I've tested this without codeigniter, and it works.I create a folder under htdocs, called "demo". I put ".htaccess" there with your content + additional line (RewriteBase):RewriteEngine on RewriteBase /demo/ # RewriteCond $1 !^(index\.php) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]Then "index.php" below:<?php echo $_SERVER['PATH_INFO'];Tested with:http://localhost/demo/helloResult: /helloThings to check:If you put ".htaccess" inside a folder, don't forget to add RewriteBase.Make sure FollowSymLinks is enabled for your directory. Seethis linkfor further information.
I am using this htaccess file on my site to remove index.php.RewriteEngine on RewriteCond $1 !^(index\.php) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]But this file doesn't work.Rewriting is enabled in Apache module.Version of codeigniter used is 2.0.1.
Codeigniter htaccess not working
scheme://username:password@host/path
I have a directory on a website that is password protected via htaccess. I want to be able to open this web page through my application without having the user enter the password but rather do it programatically.For instance, is there a way I can embed the login information in the URL? Such ashttp://www.mypage.com/page.html?htaccesspassword=asdasdasthanks!
Open htaccess password protectected page with no prompts
You're redirecting to/giftflow/index.phpcontinually. RewriteBase might help, as well as additional flags for RewriteRule. Try:RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]Additionally, CI usually auto-detects thebase_url, so you're most likely safe with leaving it blank. The logic you're defining in yourconfig.phpis probably best placed in the main index.php file as well.
On my new subdomain the homepage works fine, but everything else throws a 500 Internal Server Error. I'm sure its an.htaccessissue. I have a CodeIgniter-based web app up at GiftFlow.org and working fine.web root/var/www/vhosts/giftflow.org/httpdocsFrom my hosting control panel, I created a subdomain favorece.giftflow.org and cloned everything into it.web root/var/www/vhosts/favorece.giftflow.org/httpdocsWhen I callfavorece.giftflow.orgfrom my browser, the index page comes up fine, CSS included, but when I try to navigate to any other page I get a 500 Internal Server Error. My Apache error log says:Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.Here is my base_url in CodeIgniter's application/config/config.php$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');And my.htaccessfile, in the webroot offavorece.giftflowis:RewriteEngine on RewriteCond $1 !^(index\.php|images|assets|user_guide|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /giftflow/index.php/$1 [L]
Moving CodeIgniter install to a subdomain causes a 500 Internal Server Error
The main difference between the flags[L]and[R=301,L]is that theRflagcauses an explicit external HTTP redirect (there isone exception) while without theRflag the rule could also cause just an implicit internal redirect, depending on the actual rule and request.The optional status code just specifies the type of the redirection response.301 denotes a permanent redirect:The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link references to the Request-URI to one or more of the new references returned by the server, where possible. This response is cacheable unless indicated otherwise.The two latter sentences do also answer your question, whether such a response is cacheable.
So what is the difference?Will the browser cache the 301 and remember it?
htaccess mod_rewrite, difference between [L] and [R=301,L]
Yes,[NC,OR]is the way of combining those two flags.To combine multiplesimilarconditions into one, try this one:RewriteCond %{HTTP_HOST} ^(old-one\.com|www\.old-one\.com|old-two\.com|www\.old-two\.com)$ [NC] RewriteRule .* http://www.new-website.com%{REQUEST_URI} [L,R=301]P.S.Since you are on IIS 7, why not use their native rewriting engine (URL Rewrite module) -- yes, it has different syntax (not .Apache's .htaccess, but standard web.config XML file) but does work fine (no performance issues here on my servers).
I am using ISAPI-Rewrite on IIS7.How can we combine [NC] and [OR] in a RewriteCond ? [NC,OR] ? What is the simple way to match domains with and without "www." ?Here is a draft :RewriteCond %{HTTP_HOST} ^old-one.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.old-one.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^old-two.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.old-two.com$ [NC] RewriteRule ^(.*)$ http://www.new-website.com/$1 [QSA,L,R=301]
How to combine flags using RewriteCond?
You can't, becausedomain names are case-insensitive. In other words:Surname.comisexactly the sameassurname.com.And thecanonicalversion is the lower-case name (i.e. if you enter "Surname.com" in your browser, it will automatically be converted to "surname.com").
How to make the domain name with a capital letter?likeSurname.cominstead ofsurname.com
How to make the domain name with a capital letter?
I believe it's because of MultiViews option. TryOptions -MultiViewsin the .htaccess
I use the following .htaccess code to make my URLs cleaner:RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1 [L]It basically check if the requested URL points to a file or a directory and if it doesn't, it formats it in a particular way.The problem is that my production server seems to ignore file extensions when it checks if the requested URL points to a file. For example, it would consider the URL/contactpointing to a file namedcontact.jpgif a file with that name existed on the root of the server.What causes Apache to behave like that and what can I do to control it - make it strict about file extensions?
Apache ignoring file extensions
From thehtpasswd page:When using thecrypt()algorithm, note that only the first 8 characters of the password are used to form the password. If the supplied password is longer, the extra characters will be silently discarded.
I set up .htaccess / .htpassword and It works, except when I type the password incorrectly it still logs me in.. If I use a completely different password, doesn't work. A different user name, it doesn't work.But if I use the proper user name andmostlythe right password, it works?Example:password I'm using is "firefight", and "firefighter" seems to work. "Hose" won't.Any clue?
.htpasswd / .htaccess is letting *almost* any password work
Try thisRewriteCond %{REQUEST_FILENAME} !^.*jquery.js$ RewriteCond %{REQUEST_FILENAME} !^.*prototype.js$ RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^(.*\.)(js|css)$ minify.php?q=$1$2 [L,NC]The key to this is the inversion of the regex using the "!" (exclamation point) to say the file name is not jquery.js and not prototype.js and it can be found on the hard drive.
I need to apply a minify actions to all the javascript and CSS files, except the ones I indicate.I have this condition and rule that applies to all the files (css and js):RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^(.*\.)(js|css)$ minify.php?q=$1$2 [L,NC]I need to add the conditions to say:Apply to all except: jquery.js, prototype.js, etc..
Mod Rewrite: apply to all js and css files except
You need to use a mod_rewriteRewriteRuledirective (notRedirect)beforeyour existing rewrite.For example:RewriteEngine on # Redirect "/media/<anything>" to "/en/press" RewriteRule ^media/ /en/press [R=301,L] # Rewrite all requests to the "/public" subdirectory RewriteCond %{REQUEST_URI} !^public RewriteRule ^(.*)$ public/$1 [L]TheRedirectdirective uses simple prefix-matching, not a regex. But is also processed later in the request.And note that the URL-path matched by theRewriteRulepatterndoes not start with a slash, unlike theRedirectdirective.
I'm building a Laravel project. The project itself has a "legacy" version with a whole different structure. It's logged that some users are trying to access a file that is not found in the new environment.For a quick "fix", we want to redirect paths like/media/22044/blablabla.pdfto/en/pressThe quick solution is to useRedirect 301 /media/22044/blabla.pdf /en/pressBut we want the path behind/media/to be dynamic. I'm new with.htaccessstuff. Is there a way to do it?<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_URI} !^public RewriteRule ^(.*)$ public/$1 [L] # this one works, but not dynamic #Redirect 301 /media/2336/blabla.pdf /en/press # failed experiments #Redirect 301 (\/media)(.*)$ /en/press #Redirect 301 ^/media/(.*)$ /en/press #RewriteRule ^/media/(.*) /en/press [R=301,NC,L] Redirect 301 /media/(.*) /en/press </IfModule>
Redirect based on the beginning of the path
You will need an internal rewrite forRewriteEngine on RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteCond %{QUERY_STRING} id=([0-9]+) [NC] RewriteRule ^file\.php$ /directory/%1? [R=301,L,NC] RewriteRule ^directory/(\d+)/?$ /directory/file.php?id=$1 [L,QSA,NC]RewriteCond %{ENV:REDIRECT_STATUS} ^$condition is used to make sure that redirect rule is not executed in the next loop ofmod_rewriteafter rewriting is done from last rules.
My goal is to redirecthttp://ipaddress/directory/file.php?id=47tohttp://ipaddress/directory/47with .htaccess. Theidparameter will vary and can be any string of numbers like 1, 2, 3, 10, 20, 300, etc. My current.htaccessfile is below:RewriteEngine on RewriteCond %{QUERY_STRING} id=([0-9]+) [NC] RewriteRule (.*) /directory/%1? [R=301,L]The rewrite does change the url to what I want! But I get an error after being redirected, which states,Not Found - The requested URL was not found on this server.I'm not sure why the redirect works but does not load the previous page which had theidparameter and actual PHP file.Thank you!
.htaccess ModRewrite: Url was not found
Could you please try following. Considering that you don't want to allow any IP starting from112then we can keep it simple regex. We need NOT to mention any other digits here since you are not concerned about it.RewriteEngine on RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR] RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$ RewriteCond %{REMOTE_ADDR} !^112\. #RewriteRule ^(.*)$ - [R=403,L] RewriteRule ^(.*)$ https://www.example.com/denied.html
I thought my syntax below would work great to allow IP Ranges using an asterix as the wildcard, but no joy...Any idea what would work here?My IP changes the last two batches of numbers....<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR] RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$ RewriteCond %{REMOTE_ADDR} !^112\.*\.*\.*$ #RewriteRule ^(.*)$ - [R=403,L] RewriteRule ^(.*)$ https://www.example.com/denied.html </IfModule>
Adding a wildcard IP range to htaccess file?
Line 3 and 4 are for redirecting to https.<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </IfModule>
I would like to force https connection through .htaccess in apache for vue.js history:Vue history requires .htaccess like this:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </IfModule>How can I modify this .htaccess to force SSL connection?
Force https with vue history in apache
open this file/etc/apache2/apache2.confchnage all AllowOverride None to AllowOverride All and restart your apache after that update your permalink structure to post and update it.path can be different from "/etc/apache2/apache2.conf"
I already red a lot about this problem, but non of the solutions helped me out. I installed a fresh Wordpress on my Apache. After changing the permalink structure from default (www.domain.com/?p=id) to another one, wordpress delivers me an 404 error for each page except the homepage.I already checked the following:mod_rewrite is installed and enabled (checked through phpinfo).htaccess is read- and writableHere is my default .htaccess# 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 WordPressUsing the plugin "Debug this", I could also find out, that the rewrite rule always deliveres additional index.php? at the beginning. E.g.sitemap_index\.xml$is rewrited asindex.php?sitemap=1What can I do so solve the problem? Default links like www.domain.com/?p=1 but that kills all my SEO.Edit: After the installation, there was also/index.php/%postname%written in the custom permalink. But this setting is also returning a 404.
Wordpress post page get 404 but Homepage works
You can set these two rules in your htaccess fileRedirectMatch 301 (?i)/android-app https://play.google.com/app-urlorRewriteRule ^products$ /newPath? [L,R=301,NC]In above two rules "?i" and "NC" for case insensitive.
How I can make a robust permanet redirection from a link likehttps://example.com/productstohttps://example.com/newPathThe redirection should work case insensitive. For example the callhttps://example.com/ProDucTsshould also work.I think the solution should contain something like thisRewriteCond ????? [NC] RewriteRule ?????[L,R=301]
Apache Redirect - case insensitive
Try :SetEnvIf Request_URI ^/(api/|oauth/V2/token) noauth=1You can exclude multiple URIs. Just seperate them using the pipe symbol|.
Hi i need to protect my app during the testing phase.I read thispostabout excluding one url from Basic AuthBut i'd like to exclude 2 urls :/api/*/oauth/v2/tokenSo the entire app will be protected except for those two urls, that will be public. Otherwise i can't access my api routes.My .htaccess for now is :# Protect the app with password AuthUserFile /home/master/public_html/web/.htpasswd AuthName "Protected" AuthType Basic Require valid-userSo i'm guessing i should need some sort or regex in :SetEnvIf Request_URI ^/api/ noauth=1How can i have like a OR condition?
htaccess exclude multiple url from Basic Auth
Case 1:If/category-games/has no .htaccess then place this rule in root .htaccess:RewriteEngine On RewriteRule ^category-games/$ games.php [L,NC]Case 2:If there is a .htaccess inside/category-games/then use this ruleRewriteEngine On RewriteRule ^/?$ /games.php [L]
I have the following file/folder structure for my site:index.php games.php /category-games /category-games/game-1.php /category-games/game-2.phpThe filegames.phpis supposed to be a category homepage for/category-games/. Is there any way to make this page show when someone visitsmysite.com/category-games/? I tried to put the page into the folder and called it index.php but I guess that's not working.Probably need to do this via .htaccess. Anyone can help me with this? Right now if anyone tries to accessmysite.com/category-games/its going straight to 404.Cheers!
How to set an index page in a subfolder
for each hostname you can set up a virtual host that has it´s document root at your simfony app like:<VirtualHost *:80> ServerName domainone.com DocumentRoot "/Projects/Project/web" <Directory "/Projects/Project/web"> Options Indexes FollowSymLinks AllowOverride All Allow from All </Directory> </VirtualHost> <VirtualHost *:80> ServerName domaintwo.com DocumentRoot "/Projects/Project/web" <Directory "/Projects/Project/web"> Options Indexes FollowSymLinks AllowOverride All Allow from All </Directory> </VirtualHost>Like ServerAlias says you could also have one VirtualHost tag with multiple hostnames as ServerAliasServerName domainone.com ServerAlias domainone.com domaintwo.comIn your symfony routing configuration you can then parse the hostnamerouting_one: resource: "@yourBundle/Resources/config/routingOne.yml" prefix: /customerIdOne host: "domainone.com" routing_two: resource: "@yourBundle/Resources/config/routingTwo.yml" prefix: /customerIdTwo host: "domaintwo.com"
After hours of researches, I still can't find the answer but I am sure there is a way to solve it.I have got a Symfony app that features sites of my clients.The routing is like : /app.php/{userId}/I want to create domains (not subdomains) to point to each user page, sodomain1.com -> app.php/1/domain2.com -> app.php/2/etc...But when I try to do that with Apache hosts, I get a Symfony error : "No route found for GET /". I understand why, but I cant find a solution with Apache hosts or htaccess neither with Symfony.I dont want to duplicate my app.php or app folder.Maybe the solution is in the htaccess...What do you think about it ?Thank you in advance for your ideas :)Julien
Multiple domains on same Symfony app
Ok after much research and the help from Kevbot and Matt Thompson I was able to figure out what to do and it is as followed:You should enable all hidden files in Mac that are default hidden. To do this open a terminal (Finder > Applications > Utilities > Terminal) I originally referenced thissitebut it was wrong in regards to showing hidden files for OSX 10.8:WRONG:defaults write com.apple.Finder AppleShowAllFiles YESRIGHT:defaults write com.apple.finder AppleShowAllFiles YESAfter doing so I held down theoption+ clickingFinderat the same time to prompt Relaunch ofFinder.You will need to navigate to MAMP (in this case MAMP 3.0 non-pro) in the Applications folder toMAMP > conf > apache > httpd.conf.Open file in a text editor and search forOptions Indexes. It was line 202 for me.Change:<Directory /> Options Indexes FollowSymLinks AllowOveride None </Directory>TO:<Directory /> Options Indexes FollowSymLinks AllowOveride All </Directory>Create an.htaccessfile in the desired directory and add:Options +Indexes IndexOptions +FancyIndexingLaunch/relaunch MAMP. Do note that if you have an index anything (.php,.html..xhtml, etc. etc.) will show this instead of the directory listing
I recently purchased a new MacBook Pro (10.8 OS) and installed MAMP 3.0 (not MAMP-Pro) but I have been searching the web on how to display all files when viewing a folder within thehtdocsdirectory such as:htdocs/stackoverflowVIA the browser (Chrome or Firefox). This is a feature that I do not have a problem with in Windows using either WAMP or XAMPP when navigating to thelocalhost/directory/contents. I do understand thatlocalhostmust be accessed throughlocahost:8888or whatever port it has been modified to. I do not have an issue starting or stopping the MAMP server and everything is executable through NetBeans 8.0 when I set a.phpfile as the index:So just to be clear, if I have a directory under htdocs (htdocs/foobar/) filled with several.phpfiles I want to be able to view them in the sub-directory of htdocs instead of a blank browser (tested within Chrome and Firefox). I would imagine this is a security setting I am missing in the configuration? How would I enable, for local development, the ability to view all files, directories, and contents VIA the web browser? If it helps or may be an issue I am using NetBeans 8.0 as my IDE for PHP.Windows:localhost -stackoverflow --foo.php --bar.php --humpday.phpMac:localhost:8888 -stackoverflow --empty in browser (chrome or Firefox)I have searched to see if this aphp.inifeature,MAMP 3 documentationhas nothing on this, and Netbeans shows nothing per the search.
Display all files in MAMP htdocs through browser
I'm betting your xampp install is not very old and you're probably using a recent version of Apache. So you should usemod_deflate.mod_gzipis forApache 1.xandmod_deflateisApache 2.xYou can try this and customize as needed.<IfModule mod_deflate.c> <FilesMatch "\.(html|txt|css|js|php|pl)$"> SetOutputFilter DEFLATE </FilesMatch> </IfModule>Or you can try it this way as well.# compress text, html, javascript, css, xml: AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE image/jpeg AddOutputFilterByType DEFLATE image/png AddOutputFilterByType DEFLATE image/gif #Custom Setting End.You may also have to enable it in the Apache config. So you would uncomment this line and restart Apache.LoadModule deflate_module modules/mod_deflate.soYou can also see gzip info here.http://developer.yahoo.com/performance/rules.html#gzip
for some reason the gzip is not workingmy gzip compression script<ifModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </ifModule>i am using:----XAMPP server.last time updated:2 min before the time of this questionNOTE:ALL FILES ARE A .PHP FILE,AND .HTACCESS FILES ARE IN ROOT FOLDERHOW I FOUND OUT THAT IT IS NOT BEING GZIPPED:BY RUNNING AUDIT IN GOOGLE CHROME (DEVELOPER TOOLS)
gzip compression not working on xampp
Try adding these 2 lines in your .htaccess:AddDefaultCharset UTF-8 AddCharset UTF-8 .htm .html .css .js .woff
The following resources have no character set specified in their HTTP headers. Specifying a character set in HTTP headers can speed up browser rendering. http://www.mysite.com/assets/fonts/Roboto/Roboto300.woff http://www.mysite.com/assets/fonts/Roboto/Roboto700.woff http://www.mysite.com/assets/fonts/font-awesome/fontawesome-webfont.woffHow can I fix it via .htaccess?
YSlow: no character set specified in their HTTP headers
Here is information about how tosimulate Apache mod_rewrite $_GET['q'] routingfor a PHP App Engine app, in case that's helpful.
How do I convert this.htaccessfile to anapp.yamlfile?Here is the.htaccessfile:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(?!.*?public).* index.php [QSA,L]I need to do this to run an app using PHP on Google App Engine.The reason I'm asking this question, is because Google specifically recommends a code example in their official documentation that is stored in Git Hub called Dr Edit. The Dr Edit code example has a.htaccessfile, but noapp.yamlfile. And, in theREAD MEfile, thevery first stepfor setting up the application, is tocreate a Google App Engine application. So I guess Google has provided a code example that insinuates it will run on Google App Engine, but it won't.Supposedly Google is monitoring Stack Overflow for issues related to GAE, so I hope they read this.
What does the RewriteRule in .htaccess convert to in an app.yaml file?
There is no real difference between those 2 rules but I prefer the first rule for simplicity.Since you're not doing anything with the REQUEST_URI from the matched group there is no need to capture it as you're doing in your second rule using^(.*)$Difference is in regex pattern:^ - means match line start (will always match) ^(.*)$ - means match whole URI with 0 or more characters and capture it in $1
What's the difference between:RewriteRule ^ http://example.com/page.html [R=301,L]andRewriteRule ^(.*)$ http://example.com/page.html [R=301,L]
Difference between ^(.*)$ and ^ in regular Expressions (.htaccess)
I am guilty of writing that code more than 2 years back :PThat can be hugely simplified by this code:# remove spaces from start or after / RewriteRule ^(.*/|)[\s%20]+(.+)$ $1$2 [L] # remove spaces from end or before / RewriteRule ^(.+?)[\s%20]+(/.*|)$ $1$2 [L] # replace spaces by - in between RewriteRule ^([^\s%20]*)(?:\s|%20)+(.*)$ $1-$2 [L,R]PS:Must add that you need to fix the source of these URLs also because it is really not normal to be getting URLs like this.
I'm strugling to make this work. At the moment my htaccess contains the following code:#Debugging - Error reporting php_flag display_startup_errors on php_flag display_errors on php_flag html_errors on #Commpression <ifmodule mod_deflate.c=""> <filesmatch ".(js|css|html|png|jpg|jpeg|swf|bmp|gif|tiff|ico|eot|svg|ttf|woff|pdf)$"=""> SetOutputFilter DEFLATE </filesmatch> </ifmodule> Options All -Indexes +FollowSymLinks -MultiViews <IfModule mod_rewrite.c> # Turn mod_rewrite on RewriteEngine On RewriteBase / #RewriteCond %{THE_REQUEST} (\s|%20) RewriteRule ^([^\s%20]+)(?:\s|%20)+([^\s%20]+)((?:\s|%20)+.*)$ $1-$2$3 [N,DPI] RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /$1-$2 [L,R=301,DPI] #RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^.*\.(png|jpg|bmp|gif|css|js)$ [NC] RewriteRule ^([^/]+/?.+)$ /index.php?req=$1 [L,QSA] </IfModule>Everything works great except 1 thing if I try this url for example:http://www.domain.com/ test/the browser translates it like to:http://www.domain.com/%20test/basically after the domain if the path starts with a whitespace or a %20 it fails. can anyone please point to a solution where the starting spaces will be removed ?UPDATEThe goal:www.domain.com/ this is a test / hello there /orwww.domain.com/ this is a testtowww.domain.com/this-is-a-test/orwww.domain.com/this-is-a-test/hello-there
htaccess clean urls & replacing whitespaces and %20 with -
Open your .htaccess file in your project root. UncommentRewriteBase /drupaland change it to your project name likeRewriteBase /myprojectname. CommentRewriteBase /Goto /admin/config/search/clean-urls There will be an option to Enable clean URLs .
I just installed and started using Drupal 7, and I followed the instructions to turn on Clean Urls. I clicked "Run the Clean URL test" button, but it failed to return any results. It loads up something and then refreshes the page. There is no option to enable clean url as said in the instructions. Can somebody help ?
Enabling clean URLs (Drupal 7)
RewriteEngine On RewriteRule ^index.php/(.*)$ /$1 [R=302,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ index.php?/$1 [L]first rule redirects user non index.php site perminantly then it comes to your second rule and bingo.
This question already has answers here:How to remove "index.php" in codeigniter's path(27 answers)Closed10 years ago.I'm using below htaccess to remove index.php from my url in Codeigniter.RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]The problem is that user can still use below code to access the method :http://example.com/index.php/controller/methodHow can Iredirectthem to url without index.php or send them to anerrorpage if they add index.php ?
How to redirect and remove index.php in Codeigniter [duplicate]
Please check these configuration directives if your.htaccesshidden file is in the main root:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^index\.php/([a-zA-Z0-9_-]+)/method/param$ /index.php?url=$1 [QSA,L]It will rewritewww.example.com/index.php/$var/method/paramintowww.example.com/index.php?url=$varbut make sure that your.htaccessfile is in the main root.
Hello i have problem with my htaccess configuration in my own mvc. IDK what i do wrong? All time i have this message 500:Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.More information about this error may be available in the server error log.I want to make url rewrite to index. Try to do somthing like thiswww.example.com/index.php/controller/method/paramwww.example.com/index.php?url=controlerMy .htaccess look like this:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.+) index.php?url=$l [QSA,L]What i do wrong ?? I readhttp://httpd.apache.org/docs/current/rewrite/flags.htmland do how is there explained.
MVC htaccess rewrite
Using just:RewriteEngine On Options -Indexes RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]is fine then you can route the request within your script.You split the page variable with explode() delimiter / and then set the variables.$route = explode('/',$_GET['page']); $page = isset($route[0]) ? $route[0] : null; $subpage = isset($route[1]) ? $route[1] : null; $yada = isset($route[2]) ? $route[2] : null;Many MVC frameworks use this method. Its called routing.
I am working on making my site more SEO friendly I am currently usingRewriteEngine On RewriteRule (.*)$ index.php?page=$1To turnsite.co.uk/index.php?page=page_nameintosite.co.uk/page_nameI want to also use this for sub pages too. I have tried this:RewriteEngine On RewriteRule (.*)/(.*)$ index.php?page=$1&subpage=$2but its not working, it runssite.co.uk/page_name/sub_pagebut when you go tosite.co.uk/page_nameit returns the 404 not found.I want it to runsite.co.uk/page_nameand it returnpage_nameorsite.co.uk/page_name/sub_pageand returnsub_pageand so onsite.co.uk/page_name/sub_page/sub_page2/...
.htaccess for friendly URL with multiple variables
The keywords you are looking for are:htaccess,htpasswd,.htaccess. (Providing you use apache)Ultimately you will put a.htaccessfile in the dir you want to protect, and let it check the requirements with yourhtpasswdfile.For example: on my server I don't want people seeing myprivatedirectory.$ sudo htpasswd -c /etc/apache2/.htpasswd benjaminNotethatbenjaminin the command above ^ is the username which we will use to log in.We'd like the.htpasswdfile outside our webfolder for some security.Then in myprivatedir I'd put a.htaccessfile that contains this:AuthUserFile /etc/apache2/.htpasswd AuthGroupFile /dev/null AuthName Authenticate AuthType Basic require user benjamin
Please guide me accordingly if this question is noobish or a kind of duplicate.I am wondering how to implement this kind of authentication?I am asking because I'm quite lost and doesn't know which keywords to search for this. On my mind, I am planning to have this whenever a user wants to access my domain (eg.http://mysite.comandhttp://mysite.com/tools).
require username and password
You can always combine several flags with bit-operators.echo E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR;WithORit's easy: It's just1 + 16 + 64 = 81.You can find examples on the manual page forerror_reporting()and about bit operators on themanual page for bit operators.As a sidenote: You cannot logE_CORE_ERRORorE_COMPILE_ERRORwith PHP anyway, because they occur,beforeorduringPHPs startup process.
I current have this set in my htaccess:php_value error_reporting -1I want the log to only log fatal errors. What do I replace -1 with to do this?
what is the error_reporting number for php fatal errors only?
Create a file called.htaccessand place it in the directory this file will be in. Add this line to ti:<Files first.htm> AddType application/x-httpd-php .htm </Files>
This question already has answers here:How do I add PHP code/file to HTML(.html) files?(12 answers)Closed10 years ago.I'm programming for an Apache server and I need for just one specific html page (say, first.htm) to be processed as PHP script. Is it possible to set up?
Process specific .htm page as .php on Apache server [duplicate]
Enable mod_rewrite and .htacess. Then add this code in your .htaccess under DOCUMENT_ROOT:Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / # If the request is not for a valid directory RewriteCond %{REQUEST_FILENAME} !-d # If the request is not for a valid file RewriteCond %{REQUEST_FILENAME} !-f # If the request is not for a valid link RewriteCond %{REQUEST_FILENAME} !-l # finally this is your rewrite rule RewriteRule ^blog/(.+)$ blog.php/$1 [L,NC]
I have a url like this - www.example.com/blog.php/username, it will take you to the username's blog page, but I want to use a url like this instead - www.example.com/blog/username to get to the same file (blog.php). Please what are the steps I need to take to achieve this? Thanks for any help.
Using .htaccess to rewrite a simple url
This can be easily handled by mod_rewrite. Use this code in .htaccess under DOCUMENT_ROOT:Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / # external redirect from /index.php/foo to /foo/ RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php(/[^\s\?]+)? [NC] RewriteRule ^ %1/ [L,R] # external redirect to add trailing slash RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+((?!.+/[\s\?])[^\s\?]+) [NC] RewriteRule ^ %1/ [L,R] # internal forward from /foo to /index.php/foo RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^ index.php%{REQUEST_URI} [L,NC]After you verify that everything is working fine then changeRtoR=301.
I want user to be able use$_SERVER['PATH_INFO']as a placeholder for which file to serve and get rid of index.php in the address barFor example I want to serveme.com/index.php/settings1asme.com/settings1and so on for any PATH_INFO that the user goes to.How would I write this as a htaccess rule? I don't even know where to startIf it helps, I'm on a shared hosting plan from hostgator.Based on @EddyFreddy suggestion I tried both ways mentioned in that question with no luck. Here's what the file looks like so far:suPHP_ConfigPath /home/user/php.ini <Files php.ini> order allow,deny deny from all </Files> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC] RewriteRule .? http://mysite.com%{REQUEST_URI} [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L] # tried with and without the `?`
htaccess redirect to remove index.php
Dropping in a simple mod_rewrite rule before the mainindex.phpbootstrap capture should get you want you wantRewriteEngine on RewriteRule ^$ static-html.html [L]
Is there any way to have the Magento home page be a static html page?Under heavy load situations Magento (even with Varnish, APC, Fooman, block caching, etc) can be slow. However, I would like the home page to be as fast as possible. One way to do that is to just use a static HTML page.Is this possible?
Any way to make the Magento home page use a static HTML page?
Rewrite rulesmaybe overkill for this depending on what you want. For just your main index page, this will work...Simply adding this one line to your.htaccessfile:DirectoryIndex mysubdir/index.phpIt will display the page located atmysubdir/index.phpwhile simply showinghttp://mysite.comin the URL.I use this method myself. Whileallof my pages are located in the same subdirectory, the home page is displayed with my domain name by itself (http://www.mysite.com). All other pages show the full URL.If you also haveindexpages within deeper subdirectories and want those to come up by default within the subdirectory.Example:If you want this page:http://mysite.com/mysubdir/anothersub/index.phpto come up with this URL:http://mysite.com/mysubdir/anothersub/Then modify the line with anotherindex.phplike this...DirectoryIndex mysubdir/index.php index.phpWhat this does is tell the server to look for files with those names in that same order. If it can't find the first, it tries the second, and so on.When you're inside your root at/it finds and then displaysmysubdir/index.php.When you're inside another subdirectory like/mysubdir/anothersub/, it can't find anything namedmysubdir/index.phpso it goes to the next item and displaysindex.php
I have a website, sayhttp://mysite.com. I would like to put index.php in a subdirectory,public_html/mysubdir/index.php. I would likepublic_html/mysubdir/index.phpto get executed when the user goes tohttp://mysite.com. And I would like the url to continue to readhttp://mysite.com. Is this possible?
can I put index.php in a subdirectory, but not display subdirectory in url?