Response
stringlengths
8
2k
Instruction
stringlengths
18
2k
Prompt
stringlengths
14
160
if you are using a VPS please use this article,1.Make sure u have enabled Mod_Rewrite ? 2.Made the changes in the virtual host configurationshttps://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite
I have a very simple rewrite rule. My entire .htaccess file is as follows:RewriteEngine On RewriteRule ^login/([a-zA-Z0-9-/]+)$ company-page.php?company_url=$1 RewriteRule ^login/([a-zA-Z0-9-/]+)/$ company-page.php?company_url=$1This is perfectly run on locally Wamp server but not working on online server. It display following error.!The requested URL /EZsample/login/mereco-technologies/ was not found on this server.Can anyone help me!
.htaccess URL Rewrite Error - The requested URL was not found on this server
add the code in .htaccessRewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]and config.php file change$config['index_page'] = 'index.php';to$config['index_page'] = '';
Having problems with mod_rewrite in Fast-cgi environment for CodeIgniter. My .htaccess looks like this :DirectoryIndex index.php RewriteEngine on RewriteCond $1 !^(index\\.php|images|css|js|robots\\.txt|favicon\\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?$1 [L]But I got an error ‘No input file specified’.I changed toRewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.* - [L] RewriteCond $1 !^(index\.php|images|robots\.txt) #RewriteRule ^(.*)$ /index.php?/$1 [QSA,L] <IfModule mod_php5.c> RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> <IfModule !mod_php5.c> RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule>It works only with this one also :#RewriteRule ^(.*)$ /index.php?/$1 [QSA,L]My problem is that I still have the index.php on the URL, if I changed the configuration file application/config/config.php from $config['index_page'] = 'index.php'; to $config['index_page'] = ''; I have a different error.What I do wrong ?
How to remove index.php from codeigniter in Fast-cgi
You should download and host font-awesome on your server and call it from there
I am using the latest version of FontAwesome like this:<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> <!--[if IE 7]> <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome-ie7.min.css"> <![endif]-->It works fine in Chrome, FireFox and Safari, but when I go to Internet Explorer 10 (Older versions has the same issue), I see this error:CSS3117: @font-face failed cross-origin request. Resource access is restricted. fontawesome-webfont.eot CSS3117: @font-face failed cross-origin request. Resource access is restricted. fontawesome-webfont.woffI have tried to add the FileMatch to my .htaccess file, but that didn't do the trick.I thought that using the CSS files from FontAwesomes CDN, eliminated IE errors..Can someone please help me?
css - @font-face failed cross-origin request. Resource access is restricted.
Browsers automatically request the favicon.ico file by default.But you don't have any favicon.ico file so it is rewritten (rule in your htaccess).This is why you have a duplicate execute.Solutions:Add a favicon.ico fileDon't INSERT (in index.php) if url requested is faviconDisallow it in your htaccess with a rule
If rewrite url with .htaccess, all INSERT query with php is performed twice (unwanted duplication)My.htaccess:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>Andindex.php:<?php define('DB_LOGIN', 'mylogin'); define('DB_PASS', 'mypass'); define('DB_HOST', 'localhost'); define('DB_TYPE', 'mysql'); define('DB_NAME', 'dbname'); $mysql = MySQL_Connect(DB_HOST, DB_LOGIN, DB_PASS); $mysql_db = MySQL_Select_DB(DB_NAME); mysql_query("INSERT INTO `pages` (`title`, `slug`) VALUES ('TEST', 'test')"); ?>After one load of index.php, I have two same entries in mysql. All is OK when I remove .htaccess, so, problem must be there. The rewrite definition in .htaccess is taken from Wordpress - i like it.I try Medoo framework, but entries is still duplicate.So, any suggestion? :-)
URL rewrite with .htaccess make duplicate mysql entries
Try it$route['^nl/products/details/(\d+)$'] = 'products/$1';Using .htaccess filesOptions +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^products/(\d+)*$ ./nl/products/details/$1Using php<?php #remove the directory path we don't want $request = str_replace("nl/products/details", "products", $_SERVER['REQUEST_URI']); ?>
In my local sitehttp://localhost/giftsware/nl/products/details/2382This is my browser url for product description page now I want more user friendly url for product description page. I want to change above url tohttp://localhost/giftsware/products/2382I tried by routing all calls to details by adding$route['products/(:any)'] = "nl/products/details/$1";this is in routes.php file, but it gives me 404 error. What could be the possible issue and how can I fix it?this is my complete route file code$route['(:any)/products/(:num)'] = "products/details/$2"; $route['default_controller'] = "pages"; $route['404_override'] = ''; $route['^en/admin/([a-zA-Z_-]+)/(:any)'] = '$1/admin/$2'; $route['^en/admin/(login|logout)'] = 'admin/$1'; $route['^en/admin/([a-zA-Z_-]+)'] = '$1/admin/index'; $route['^nl/admin/([a-zA-Z_-]+)/(:any)'] = '$1/admin/$2'; $route['^nl/admin/(login|logout)'] = 'admin/$1'; $route['^nl/admin/([a-zA-Z_-]+)'] = '$1/admin/index'; $route['admin'] = 'admin'; $route['pages/(:any)'] = "pages/index/$1"; $route['^nl/(.+)$'] = "$1"; $route['^en/(.+)$'] = "$1"; $route['^nl$'] = $route['default_controller']; $route['^en$'] = $route['default_controller'];
product detail page routing in codeigniter
If your default url starts with www (like www.domain.com) then your translated urls will look like en.www.domain.com.But if you try to login en.domain.com, you may think that your plugin doesn't working.Before try anything be sure that any subdomains shows your WordPress homepage. With default settings WordPress should not redirect to you anywhere.Then set your default url without www prefix (for ex. domain.com)And check the permalink finallyIf you fail at any steps, disable all plugins and even change your theme to default one.
Im running a WordPress site with qTranslate installed. The URLS are currently displayed ashttp://domain.com/en/but i would like to change them tohttp://en.domain.comHow do i make this work? qTranslate has a built-in pre-domain mode, which should do exactly what i need. But all it does is change the links (works), when visiting the page i get a 404 error.In the admin it says "Pre-Path and Pre-Domain mode will only work with mod_rewrite/pretty permalinks. Additional Configuration is needed for Pre-Domain mode!"I got pre-path working and i think im using pretty permalinks (/%category%/%postname%/), but ive got no idea what kind of 'additional configuration' is needed.My .htaccess looks like this (i think standard wp output);<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>I tried a lot of different things found online, but i mostly get internal server errors or just the 404.Thanks in advance!
.htaccess subdomain languages
Rewriting to a CGI script is your only option from a .htaccess, technically you could use a programaticRewriteMapwith a RewriteRule in ahttpd.conffile.The script can serve the file directly, so with an internal rewrite the logic can be entirely server side e.g..htaccess RuleRewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-s RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^images/(.*)$ /getLatest.php [L]WheregetLatest.phpis something like:<?php $dir = "/srv/www/images"; $pattern = '/\.(jpg|jpeg|png|gif)$/'; $newstamp = 0; $newname = ""; if ($handle = opendir($dir)) { while (false !== ($fname = readdir($handle))) { // Eliminate current directory, parent directory if (preg_match('/^\.{1,2}$/',$fname)) continue; // Eliminate all but the permitted file types if (! preg_match($pattern,$fname)) continue; $timedat = filemtime("$dir/$fname"); if ($timedat > $newstamp) { $newstamp = $timedat; $newname = $fname; } } } closedir ($handle); $filepath="$dir/$newname"; $etag = md5_file($filepath); header("Content-type: image/jpeg"); header('Content-Length: ' . filesize($filepath)); header("Accept-Ranges: bytes"); header("Last-Modified: ".gmdate("D, d M Y H:i:s", $newstamp)." GMT"); header("Etag: $etag"); readfile($filepath); ?>Note: Code partially borrowed from the answers in:PHP: Get the Latest File Addition in a Directory
I want to create .htaccess rule for situation like below:I have a link to file:http://something.com/images/some/image_001.pngIf this file doesn't exists I want to redirect to the newest file in /images/some directoryIs something like this possible using .htaccess? I know that I can check if file exists with RewriteCond, but don't know if it is possible to redirect to the newest file.
Can I redirect to the newest file in directory using .htaccess?
This should work :RewriteCond %{HTTP_HOST} ^([a-z0-9\.-]+)\.com\.$ RewriteRule ^(.*) http://www.domain.com/$1 [QSA,L,R=301]
Many websites can be accessed with aFQDN(i.e., appending a dot to the TLD):https://www.ebay.com./https://www.google.com./https://www.reddit.com./https://stackoverflow.com./https://en.wikipedia.org./wiki/Main_PageSome sites can’t be accessed that way, but I can’t find an example right now.¹ ²Is it possible, within a.htaccessfile, to redirect all variants with the dot suffix to the variants without?Ideally with a "wildcard" rule, so that you don’t have to list the domains explicitly (for using it on different sites/domains without editing).Example redirects:http://example.com./→http://example.com/http://example.com./foo→http://example.com/foohttp://sub.example.com./bar.html→http://sub.example.com/bar.html¹ stackoverflow.com, when accessed over HTTP, used to give HTTP error 400: "Bad Request - Invalid Hostname".² Wikipedia, when accessed over HTTPS (when it was still optional), used to give a certificate error: "The certificate is only valid for the following names:*.wikipedia.org,wikipedia.org(Error code: ssl_error_bad_cert_domain)
Redirect URLs with FQDN (dot after TLD) to equivalent with PQDN
I assume that your additional domain has a different host: addondomain.com ?In this case, simply add this condition to your .htaccess:RewriteCond %{HTTP_HOST} maindomain.com$ [NC]So the full redirection rule would look like this:RewriteCond %{HTTP_HOST} maindomain.com$ [NC] RewriteRule /index.php$ http://www.maindomain.com/blog/ [R]
I have a domain name maindomain.comIn the main domain I have a blog. The main domain is not active now. So all requests to site root index.php is redirected to maindomain.com/blog using htaccess.I have this in htaccess for redirectionRedirect /index.php http://www.maindomain.com/blog/ Options All -IndexesEverything works fine.Now I added an Addon domain. The addon domain root folder is maindomain.com/addondomain.comaddondomain.com folder has an index.php. When I am accessing addondomain.com in the browser its getting redirected tohttp://www.maindomain.com/blog/How to prevent this?
.htaccess redirect main domain and addon domain issue
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]Remove the L in the[R=301,L], which means "Last", which means "stop processing RewriteRules after this one."The 301 also means "redirect permanently." In this case, your browser will remember the permanent redirect. Is it possible that you had one version of your rewrite rules, went to your URL, and then changed it? Clear your cache or try another browser.
My .htaccess file is as follows:Options -Multiviews RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com RewriteRule ^(.*)$ http://www.example.com/$1 [R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.phpThe issue that I am having is that when I try to access my site without the www. prefix, the .php extension is added to the address, which can often cause a problem. For example, if I try to access my homepage with the address example.com, that address is transformed into www.example.com/.php. I want the www. to be added, but the .php extension added at the end just causes an error. How do I fix this?
mod_rewrite Adds .php Extension
Just after I posted my question, I came to a solution towards the following:Mimic the default server configuration's<Files>rules for.httype of files.Allow them.Redirect them to 404.Works like this:<Files ~ "^\.ht"> Order Deny,Allow Allow from all Satisfy All Redirect 404 / </Files>
This is sort of a follow-up toIs there a way to force apache to return 404 instead of 403?which suggestedRedirectMatchto 404 to accomplish this.It works perfectly fine for most of anything, however if I request:http://example.com/.htaccessI get a 403 and not a 404 if I have (or not) this in my.htaccessfile:RedirectMatch 404 ^/\.htaccess$Is there a way to override the default 403 - Forbidden behavior of apache from inside the.htaccessfile itself?
Requests to .htaccess should return 404 instead of 403
It looks like this is interfering with mod_dir, which by default redirects the browser when it tried to access a directory and the trailing slash is missing. What's happening is the Rewrite is occuring, changing/siteto/versions/020/sitethen mod_dir is redirecting the browser tohttp://domain.com/versions/020/site/. Thus the browser sees the versions/020 stuff in the location bar.You can turn off mod_dir's automatic redirect with the"DirectorySlash Off" directive. But you may want to add the trailing slash anyways by including a redirect before any rewrites happen.RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+[^/])$ $1/ [R,L]This or something equivalent before you do the rewrite to/version/020should hopefully fix it.Edit: Actually, now that I'm thinking about it, if you rewrite/redirect when trailing slash is missing, you don't need to turn offDirectorySlashbecause it'll always have a trailing slash by the time it gets to mod_dir. Maybe do it anyways to be safe?
I'm using the following rule to use folders for different versions:RewriteEngine On RewriteRule .* - [E=VERSION:020] RewriteRule ^versions/(.*)$ versions/$1 [L] RewriteRule ^(.*)$ versions/%{ENV:VERSION}/$1 [L]I have a structure like:http://domain.com/versions/020/ http://domain.com/versions/020/th?=1 http://domain.com/versions/020/myfolder/ http://domain.com/versions/020/myfile.htmlBut the user can see:http://domain.com/ http://domain.com/th?=1 http://domain.com/myfolder/ http://domain.com/myfile.htmlI have a last problem with a slash that shows the version number.A second entry point is (still working):http://domain.com/site/But the problem when the user type the url and omit the end forward slash, like this:http://domain.com/siteThe user now see the version number like this:http://domain.com/versions/020/site/This is a problem as I don't want the user to find out about other versions.Any idea how I can solve the problem?
Rewrite module to handle site version folders (strip slash)
Well, after your comment I can say that your friend is wrong. Google bot will never be redirected on the same page (index.php in your case). Of course is not very good that in each page url you have the "index.php" because you are losing important chars which otherwise can be used to put keywords.Said that, your site will be indexed normally. Infact, many Joomla-based websites have the same behavior as you can see on this website (parlaritaliano.it) which is very well indexed on Google.Anyway, I advice you to replace (using.htaccess) the index.php in every of your urls because it isbetterfrom a SEO point of view. I repeat...better, it does not will cause any Google bot loop.
I made one website xyz.com using php codeigniter framework. This website has modules, so modular extension is used. Now when this website is made live, every link shows index.php. So for this we can use .htaccess for modrewrite command. Till now my knowledge was cool enough. Now when my friend who has good knowledge of SEO saw my website links, he told me that your website will not come above(lower ranks) in google.His reason is - your every request is pased through index.php. When google crawls your site, it will be redirected again to index.php which is main drawback. As he didnt have much knowledge about codeigniter, he told to fix this index.php issue as soon as possible. So I wanna knowIS HE GIVING A VALID REASON?? if yes...so how can I solve this problem.Anything related to this issue from your side is also welcomed, as I may not have asked complete question.
What .htaccess redirection has effect on Google bot?
Optionally match the last/. Change your .htaccess file to this:RewriteEngine On RewriteRule ^(.*)/?$ public/$1 [L]
I have strange for me problem. I'm developing Zend Framework application and have this file structure:/ /application/ /public/ /public/.htaccess /public/index.php /public/js/ /public/style/ /public/profile/ /.htaccessMy domain point tofolder /When I enter the addressexample.com/profile/it goes to the controller profile and this is good. When I enter the addressexample.com/profilethe server redirects me to:example.com/public/profile/I would like to have a solution that whenever I request:example.com/profile/orexample.com/profileThe same page will be rendered but second version gives me a redirect and I don't know why.The/.htaccessfile is:RewriteEngine On RewriteRule ^(.*)$ public/$1 [L]The role of this file is to route all traffic from / to /public but without any redirects.The/public/.htaccessfile is:RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]Can anybody help me with this? Thanks.I fixed this. Here is the solution if somebody have the same problem: To fix this you have to set the following options and disable DirectorySlashOptions -Indexes FollowSymLinks DirectorySlash OffNow Apache shouldn't add trailing slashes at the end of uri when you pointing to directory. This also disable redirect to the uri with trailing slash.
htaccess redirects unexpectedly to folder
If you use Apache you can use the mod_rewrite module for this.http://httpd.apache.org/docs/current/rewrite/I'm sure IIS support somthing like that to.
I want a folder name not to be displayed in address bar. Example: hiding "members" folder:www.mysite.com/members/jonesmith/index.phpwww.mysite.com/members/tome/index.phpwww.mysite.com/members/jerry/index.php...etcI want to put those links like this:www.mysite.com/jonesmith/index.phpwww.mysite.com//tome/index.phpwww.mysite.com/jerry/index.php...etcand when the link is clicked the address bar will show the same, i.e, without "members".I need this make the pages of the members or the urls short.Of course any link clicked within the pages of the member will not show the "members" in address bar.Shortly: the folder "members" exists but it will not be visible to the visitors in every level.Any idea using php script, javascript, .htaccess ..etc?
skip a folder name in path while displaying in address bar
the .* should be caught between () this way the system knows it is suppose to "memorize" the expression as $1.
I'm trying to rewrite every request to the parent directory.This is the content of my .htaccessRewriteEngine on RewriteRule ^(.*)$ ../$1Unfortunately this isn't working and causes a 'Bad Request' error. Is this possible?
.htaccess rewrite everything to parent directory
Make sure this website is configured to respond to *.mydomain.com.RewriteCond %{http_host} ^www.(\w+).mydomain.com [NC] RewriteRule ^.*$ /myfile.php?name=%1 [L]You might want to adjust^.*$, since this check will rewrite regardless of what comes after www.companyname.mydomain.com.
I want to set a subdomain for all site users, like www.companyname.mydomain.com I would like to use htaccess for this.when somebody requests www.companyname.mydomain.com it should redirect to myfile.php?name=companynameHow can I achieve this using an htaccess file ?Thanks for the consideration.
Setting subdomains using htaccess
Basically, you'll want to point all your domains to the same directory (maybe using a wildcard in yourvhosts) and then setupurlrewrite; look atthis questionfor an example, and it can be in a .htaccess file or Apache configuration.All requests that come in will go to the same gateway.php and you can extract the current domain and requests using$_SERVER['REDIRECT_QUERY_STRING'],$_SERVER['REQUEST_URI']and $_SERVER['SERVER_NAME']for example. See$_SERVER. You'll then be able in your gateway.php to send the correct files.
I have been looking for a while now to find a solution to accomplish the following system.I would like to build a PHP system on, let's say, domainA. On this domainA I will allow an administrator to 'create' a new website. This website contains only of pieces of text, which are all stored in a database. This, I know how to do.However, now I would like to make it possible that visitors that surf to domainB will be invisibly redirected to for example domainA.com/gateway.php?refdomain=domainB&page=xxx or something similar. I have a vague idea this should be done by .htaccess, but I don't really know how I can do this in the most easy way. If for example there are some POST or GET requests on domainB, this should keep working. Also images linked tohttp://www.domainB.com/test.gifshould be invisibly loaded form www.domainA.com.I also know there are some CMS systems (eg drupal) which allow this feature, so it is possible, I just don't know how.Thank you for any advice that might point me in the right direction, kind regards, Digits
Manage multiple websites from one domain
Your .htaccess does nothing useful, as Apache is probably configured with DirectoryIndex index.php. Well, it does move domain.com/a to domain.com/index.php, but I doubt that is what you want.Your wildcard virtualhost works because you probably have ServerAlias *.domain.com in your configuration, or a single virtualhost and DNS pointing to the address of your server. (When you have a single virtualhost, it shows up for any request, and the first listed virtualhost is the default one)You have to create new VirtualHosts for the static domains, leaving the default one as, well, the default one :)Checkthesetutorialsthat explain it all.
I have a wildcard subdomain enabled and dynamically parse the URL by passing it as-is to myindex.php(ex.somecity.domain.com).Now, I wish to create a few subdomains that are static where I can install different application and not co-mingle with my current one (ex.blog.domain.com).My.htaccesscurrently reads:RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]Can I manipulate this.htaccessto achieve what I need? Can it be done through Apache?
Wildcard Subdomain Exceptions
The problem is that thedeny from alldenieseverythingincluding the error documents.But hey, .htaccess files work in cascade, so you cancreate a subfolder in your web root (assuming your webroot is/www-/www/errordocs=> in there put your ErrorDocuments like 403.html etc.create another.htaccessthere-/www/errordocs/.htaccess=> into this/www/errordocs/.htaccessputallow from allIn the main.htaccessin the webroot (/www/.htaccess) putErrorDocument 403 /errordocs/403.htmletc..If this is still not working for you, check there are public/others/everyone READ permissions on both the folder and the file/www/errordocs=>755/www/errordocs/.htaccess=>640/www/errordocs/403.html=>644Don't be confused - Windows OSalsohas permissions, you will need at least Read permissions forEveryoneon these,more on the Windows permissions here.Just remember, files in this folder will all be public!(don't put there anything you don't want public :-)
I want to have a custom 403 page in my project. So I added these codes in a .htaccess file:Order deny,allow Deny from all Allow from 192.168.1.0/24 ErrorDocument 403 /403.htmBut when the project runs from an out of rang IP, and 403 error must be occurred, custom 403 page redirect does not work and I give another error too.ForbiddenYou don't have permission to access /app/ on this server.Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.What is this problem for? I have read different articles inside StackOverflow and other websites, but none of them could not solve this problem.
htaccess 403 Forbidden error was encountered while trying to use an ErrorDocument
Which theme your using to develop a website?? I think your theme is a issue.. Change any other default theme of wordpress such as twenty sixteen and check the issue.. If it is worked, your theme has some problem..
I develop one website in wordpress. but now days i am facing one error:require(public_html/mywebsite/wp-includes/post.php):failed to open stream: permission denied in public_html/mywebsite/wp-settings.php on line 142====================================================================Fatal error: require(): Failed opening required '/public_html/mywebsite/wp-includes/post.php'(include_path='.:/opt/apt/php55/usr/share/pear:/opt/alt/php55/usr/share/php') in /public_html/indus/wp-settings.php on line 142to solve this i changed permissions of post.php file. and it worked. but on next day when i tried to open it, again i faced same problem.how to solve this?
require(public_html/mywebsite/wp-includes/post.php):failed to open stream: permission denied in public_html/mywebsite/wp-settings.php on line 142
Best way to do it ..Is to use .htaccessHere is website that will generate htaccess country block codes:http://www.ip2location.com/blockvisitorsbycountry.aspx
I want to restrict which country can access my webpage, but I can't get it to work.I tried followingthis guide.It gives me lots of error when it is hosted on my localhost (XAMPP). Check error from screenshot:And if it is uploaded to some free hosting it gives me an infinite "LOOP" when accessingdomain.com/index.phpordomain.com/redirect.php.But onthis webpageit works, and shows my details perfectly (country, country code, latitude, longitude etc.)I've pasted those two files on the same folder and trying it to access on my computer which is:http://localhost/geoplugin.class/index.php
Country based redirection
I cannot give comment, so i'll try here instead.you need to remove this line from .htaccessRewriteRule ^(.*)/$ /$1 [L,R=301]or add # in front of it to comment.
This question already has answers here:laravel trailing Slashes redirect to localhost(4 answers)Closed6 years ago.My application url is:http://localhost/my-appAnd my admin panel is here:http://localhost/my-app/adminBut when I try to access the admin panel using this url:http://localhost/my-app/admin/It redirects me to :http://localhost/adminIs there any way to prevent this by happening? I want to access the admin panel from this url also.My htaccess file looks like this currently:<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # 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] </IfModule>
Laravel 5: Prevent redirection when the url ends with “/” [duplicate]
I tried asanubhavasaid in hisanswerRewriteRule ^do_something\.php$ - [L,NC]and it didnt worked for me but i managed to solve it by redirecting this files to my front controller:RewriteRule ^example/(.+)\.php$ %{ENV:BASE}/app.php [L]So in this case if someone enter the pathexample/do_something.phpthe file wont be served and the request goes by front controllerFull example:# If the requested filename exists # And my route path for controller action is the same # Don't serve file serve action RewriteRule ^example/(.+)\.php$ %{ENV:BASE}/app.php [L] # If the requested filename exists, simply serve it. # We only want to let Apache serve files and not directories. RewriteCond %{REQUEST_FILENAME} -f RewriteRule .? - [L] # Rewrite all other queries to the front controller. RewriteRule .? %{ENV:BASE}/app.php [L]
I'm facing a problem withhtaccess, i want to write a condition that will prevent to serve specified file.If the requested filename exists, simply serve it so i have this:RewriteCond %{REQUEST_FILENAME} -f RewriteRule .? - [L]but how can i achive that one specified file will not be served ? i have this path used for my controller action. so for exampleexample/do_something.phpis the path to filedo_something.phpbut also is the path to my controller action and i want myhtaccessfile to serve this action instead of this file but only this.
How to write rewrite condition for request_filename different then specified
All you have to do is remove the content before the svg opening tag.It works for me here jsfiddle.net/LguDF/
I have been searching the web for the past few days to solve my problem and exported my file different ways from Illustrator and it all ends up the same. I have edited my .htaccess file to include "AddType image/svg+xml svg AddType image/svg+xml svgs" and it still doesn't work for me. I am using the object tag because I want to have a fallback image for older devices and browser. SVG's do work when I use the SVG tag however, but not the object tag. Here is a picture of what I see:http://bit.ly/1cFzctgI have tested it on a macbook pro running 10.9, in Safari and Chrome. Here is the siteTesting Site, I have created a blank html page with just the SVG element on it. I have included a picture of what I see.Thank you for any help.
SVG Image File Shows XML Code Instead Of Image
I mean, here's my very bad solution, which appears to work:Change the paths in the jbimages dialog to the form:http://my.sites/matadev/app/webroot/js/tinymce/plugins/jbimages/ci/index.php/blankand the 'img_path' in jbimages' config.php to/myapp/app/webroot/imgbut obviously this is just stepping around the problem, and avoiding a real understanding of why CakePHP's .htaccess setup is ceasing to work once inside the depths of the TinyMCE plugin...
I'm trying to install the JustBoil.me image upload plugin for TinyMCE HTML editor as part of a CakePHP application.However, when I try to upload an image it gets nowhere. Investigation reveals the following two requests are 404ing:http://my.sites/myapp/js/tinymce/plugins/jbimages/ci/index.php/blankhttp://my.sites/myapp/js/tinymce/plugins/jbimages/ci/index.php/upload/englishSure enough, when I try to accesshttp://my.sites/myapp/js/tinymce/plugins/jbimages/ci/index.php/blankin a browser I get a 404 Page Not Found. However, I get a different result from expanding this url tohttp://my.sites/myapp/app/webroot/js/tinymce/plugins/jbimages/ci/index.php/blank.My .htaccess files are standard for CakePHP (I think), i.e. in myapp:<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>in app much the same (but for webroot instead of app/webroot) and then in webroot:<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] </IfModule>Is there something simple I can do to make sure thathttp://my.sites/myapp/js/tinymce/plugins/jbimages/ci/index.phpdoesn't flake out due to (?) the lack of /app/webroot/ in the path?
TinyMCE plugin interacting badly with .htaccess
Here's a few solutions:Pretty URLs without mod_rewrite, without .htaccessAlso, I guess you can run a script tocreate the files dynamicallyfrom an array or database so it generates all your URLs:/index.html/about/index.html/contact/index.html...And hook the script on every edit, in a cron or run manually. Not the best in terms of performance but hey, it should work.
My question pertains specifically to the two pages below, but is also more generally relating to methods for using clean URLs without an .htaccess file.http://www.decitectural.com/andhttp://www.decitectural.com/about/The pages above are hosted on Amazon's S3, which does not allow for the use of htaccess files. As a result, I have found no easy way to create a clean url rewrite scheme that sends all requests to an index file which, in turn, interprets the URL using javascript and loads up the correct page (with AJAX, or, as is the case with decitectural, with simple div visibility toggling).In order to circumvent this problem, I usually edit the amazon S3 bucket properties and set both the index page and the error page to the index.html file. In this case, the index.html file is served even when an invalid path (such as /about/) is requested. This has, for the most part, been a functioning solution... That is, until I realized that I was also getting a 404 with the index.html page which would stop Google from indexing it.This has led me to seek out an alternative solution to this problem. Currently, as a temporary fix, I am actually creating the /about/ directory on the server with a duplicate of the index.html file in it. This works, but obviously is not a real solution to the problem.I would appreciate any advice on how to set up a clean URL routing scheme on S3 or in any instance where an .htaccess file can't be used.
single-page application with clean URLs without .htaccess file?
Ok so after trying with no success i finally decided to incorporate a portion of your suggested .htaccess code along with some .php. I have the .htaccess file get the request method and send it to the index.php, the index.php file then says if its == 'POST' do something else do something else and it works..htaccessRewriteEngine On RewriteRule ^(.*) index.php?request=%{REQUEST_METHOD} [L,QSA]index.phpif ($_GET['request'] == 'POST') { } else { }
I have been looking around for ways to deny all HTTP methods but POST. Yes i realize this might not prevent much but i would like to make it work. I came across a way to deny all but post using the .htaccess file:RewriteEngine On RewriteCond %{REQUEST_METHOD} !^POST RewriteRule ^.*$ /home/user/public_html/folder/bad_request.phpNow in my iphone app i have the following code which POST's data to the website:NSString *post_length = [NSString stringWithFormat:@"%d",[post_data length]]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://folder.domain.com/"]]; [request setHTTPMethod:@"POST"]; [request setValue:post_length forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:post_data];When i run this code with my current .htaccess as shown above i get the bad_request page as if i wasnt POSTing data but if i change the .htaccess rule to !^GET i can visit it in the browser and gain access but when i post with the iPhone code i get denied...so that works backwards. Does anyone have an idea why it wont work?
.htaccess Deny All But POST Not Working With Objective-C
Everything is being routed through wordpress so when a request for something like/sub/no_file.htmland it doesn't exist, wordpress routes it through itsindex.phpbecause it satisfies both the!-fand!-dconditions (not an existing file and not an existing directory). It then decides that it can't find the resource for/sub/no_file.htmlso it then displays its own 404 file.If you want requests that go to /sub to bypass wordpress' routing so that if a file is requested in/sub/that doesn't exist,/404.htmlgets served, you can add this line right beforeRewriteRule . /index.php [L]in your wordpress rules so that they look like this:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/?sub/ RewriteRule . /index.php [L] </IfModule>
On a subdirectory such ashttp://website.com/sub/index.htmlthat has it's own .htaccess is still for some reason showing the 404 page I have for Wordpress which is on the directory above this one..htaccess for sub dir:ErrorDocument 404 /404.html.htaccess for main dir:RewriteEngine on RewriteCond %{HTTP_HOST} ^website.net$ [OR] RewriteCond %{HTTP_HOST} ^www.website.net$ RewriteRule ^foghelper.php$ http://website.net/subdirone/ [R=301,L] RewriteRule ^foghelper.php$ http://website.net/subdirtwo/ [R=301,L] # DO NOT REMOVE THIS LINE AND THE LINES ABOVE jNLK5d:REDIRECTID # 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 WordPressLinks that were in the hta were censored in case your wondering.Edit:Upon addingRewriteCond %{REQUEST_URI} !^/?sub/beforeRewriteRule . /index.php [L]the error still seems to exist.
WordPress 404 template overriding my .htaccess settings for 404 errors?
This is what the total solution was:If anyone else needs to know, I created a snippet called passwordprotect and put at the top of the page: [[passwordprotect]]. I then put in the following code (an adaptation of the above response):<?php if(isset($_SERVER['PHP_AUTH_USER']) && ($_SERVER['PHP_AUTH_USER']=='user') && ($_SERVER['PHP_AUTH_PW']=='password')) { echo 'You are successfully logged in.'; } else { header('WWW-Authenticate: Basic realm="Protected area"'); header('HTTP/1.0 401 Unauthorized'); echo 'Text to send if user hits Cancel button'; exit; }EDIT: If you are finding that this sometimes does work and sometimes doesn't work, this is probably because using [[passwordprotect]], modx will cache the snippet. I got better success with: [[!passwordprotect]] on Revolution. I think the code is [!passwordprotect!] on Evolution. The exclamation marks just denote not to cache the snippet. Hope that helps someone!
We are trying to protect a couple of different resources in our ModX installation. The current .htaccess code is as follows (not including all of the ModX stuff)AuthName "Dialog prompt" AuthType Basic AuthUserFile /var/www/vhosts/mywebsite.co.uk/.htpasswd <FilesMatch ^index.php\?q=71$> require valid-user </FilesMatch>The object of the exercise is to protect the following resources:http://mywebsite.co.uk/index.php?q=71http://mywebsite.co.uk/area/protectedI have tried various combinations of LocationsMatch, Locations, Files and Filesmatch and can't get it to work.Thank you in advance
How do I password protect resources in a ModX Website using htaccess and htpasswd?
I just had the same problem and found you page...If you have domain/folder and want to redirect anything from the folder back to the domain's index, useErrorDocument 404 /...I'm not sure if this goes to the root folder or one folder up, but in your case (and mine) they are one in the same.Hope this helps!
I have a htaccess file in a sub folder like so:/subfolder/.htaccessIn the htaccess file the following code to set a 404 ErrorDocumentErrorDocument 404 /404.phpThe issue is the 404 page in the root directory is loaded rather than the one in the/subfolder/folder. I can't simply change the htaccess file to use /subfolder/404.php because the system is going to be installed in lots of different places.Is there a way to reference the files in the directory that the htaccess is in?
Use 404 ErrorDocument that is in a sub directory
Functionally, I think they are much the same, with some minor pros and cons. However the former is probably more portable, since you won't have worry about mod_rewrite being installed on the server should you move the site at some point in the future.Naturally, if you have other mod_rewrite rules this won't make much difference to you.You also have a wildcard set up in the mod_rewrite rule, that isn't present in SetEnvIfNoCase. I understand this is possible to do this there also, and it might be wise to do so, since you can then catch different libwww versions.I'm sure you know libwww-perl can send an arbitrary user agent string, so neither will stop the determined.
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed11 years ago.Improve this questionI want to know the difference between these rules and which is most effective to block libwww-perl with the file .htaccessSetEnvIfNoCase User-Agent "libwww-perl" bad_bot Order Deny,Allow Deny from env=bad_botorRewriteCond %{HTTP_USER_AGENT} libwww-perl.* RewriteRule .* – [F,L]Thank you!
Difference between Apache rules to block libwww-perl [closed]
Are you married to using htaccess authentication? You'll have greater flexibility if you use authentication through PHP instead.http://php.net/manual/en/features.http-auth.php
I have a site hosted on Apache which contains some protected content. I want to provide access to this protected content to users that are authenticated in another application. The content is protected using htaccess and htpasswd.I would like to use curl to set the username and password, then redirect the user to the protected folder. I can do this easily if the protected content is a single file, but my solution seems to only work for the one page. As soon as the user clicks a link and tries to access another page, the session is lost. There are hundreds of pages in the directory.Here is the code I am using:$ch=curl_init(); curl_setopt($ch, CURLOPT_URL,'http://domain.com/protected_folder/'); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, "username:password"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_exec($ch); curl_close($ch);I have two problems with the results:A full redirect is not done, so any links that are clicked are referencing back to the folder where the php file resides, not the protected folder. The address bar still shows the path to the php script.It appears the session is lost immediately. Any attempt to access resources in the protected folder is prompted with a login box.Any ideas on how to resolve either of these two issues would be greatly appreciated.
php curl - Need to provide access to a protected directory using curl
Try theB flagto ensure the%25, unescaped to%by mod_rewrite, is re-escaped back to%25when inserted back into the target path.RewriteRule .* index.php/$0 [PTB]
Having percent sign inside URL, returns bad request (error 400) to the browser. I have a filename that have percent (%) sign, resides at server.Original File name:204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1,2%.pdfURL in browser after clicking on download link:http://www.example.com/204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1%2C2%25.pdfThis returns 400 error with "bad request". I am using Kohana 3.Existing.htaccessfile contents are as follows:RewriteEngine On RewriteBase / <Files .*> Order Deny,Allow Deny From All </Files> RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT]
htaccess to escape percent (%) from URL
Refer to this Apache doc page for examples of what you might want to do. It covers most cases of redirecting, blocking, etc. from direct domains and referring sites.http://httpd.apache.org/docs/2.2/rewrite/access.html#blocked-inline-images
Recently, my wordpress website has been experiencing a spike in hack attempts by various IPs but they all have the same user Hostname:A user with IP address xxx.xxx.xx.x has been locked out from the signing in or using the password recovery form for the following reason: Used an invalid username to try to sign in. User IP: 91.121.156.62 User hostname: ks359219.badhost.comA user with IP address xxx.xxx.xx.x has been locked out from the signing in or using the password recovery form for the following reason: Used an invalid username to try to sign in. User IP: 5.135.182.147 User hostname: ks3289006.badhost.comA user with IP address xxx.xxx.xx.x has been locked out from the signing in or using the password recovery form for the following reason: Used an invalid username to try to sign in. User IP: 5.135.185.89 User hostname: ks3290602.badhost.comA user with IP address xxx.xxx.xx.x has been locked out from the signing in or using the password recovery form for the following reason: Used an invalid username to try to sign in. User IP: 5.39.86.162 User hostname: ks3273571.badhost.comThe security plugin I am using seems to be fending them off, but I would like to be able to block all requests from ANY IP that is associated with the user hostname using a wildcard like xxx.badhost.comThe plugin lets me block a range of IPs such as 123.12.1.* but not hostnames. What would be the best way to block these hacking attempts? .htaccess? Thanks
block requests by user hostname using htaccess
For the mass sign-up part, a simple and effective captcha should do the work.
We've recently had a client get hammered with bots signing up for accounts as well as looking for directories that don't exists (/phpmyadmin/, /pma/, /members/, /admin/, etc.). We've created a way to scrape through the access logs and identify the malicious IP's, however I'm wondering the most effective solution.After the initial scrape, I tried adding about 10,000 IP's to iptables to be blocked. This seemed to make things a little slow and I started to wonder what would be best to block the offending bots/malicious users. Using iptables, htaccess, or simply a database. The database approach seems the simplest, but I'd rather not have the malicious users wasting a query if it is more efficient to block them at the htaccess or iptables level.Is there a method that is preferred for large amounts of addresses? What are the considerations, if any, for each?This is a simple webserver running a PHP/MySQL application.Thank you.
Blocking Unwanted Visitors: htaccess, iptables, or just database
The bit with the hash in the URL is not sent to the server when requesting a page, so you can't use redirect rules like that. It's client-side only.
How can I remove the hash sign (#) from the page's URL ? I am using the SWFAddress plugin (jQuery) for deep linking purposes.I need to replace thislocalhost/site/#blogbylocalhost/site/blog(Yes, #blog is just an anchor).Somehow url rewriting in .htaccess doesn't workRewriteRule /blog #blog [L]Any suggestions ?
URL rewriting - removing hash
You wantDeny from all
It is probably very simple but I can't find it. I want to make a .htaccess file so no one can get into the folder. except for the php on the server.does anyone know the code line?Thanks Matthy
Give no one access in a directory .htaccess
apt-get install libapache2-mod-php5just did the job. Now I'm not sure if the changes apache2.conf actually caused the problem...
i tried to protect a directory in my www-folder by using a .htaccess file which had no effect so i changed lineAllowOverride Nonein my apache2.conf toAllowOverride Allas root.now i see that this wasn't the right way to do it. when trying to restart apache using/etc/init.d/apache2 restart (or stop and start)I'm getting the following error message:[FAIL] Starting web server: apache2 failed! [warn] The apache2 configtest failed. ... (warning). Output of config test was: apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/php5.load: Cannot load /usr/lib/apache2/modules/libphp5.so into server: /usr/lib/apache2/modules/libphp5.so: cannot open shared object file: No such file or directory Action 'configtest' failed. The Apache error log may have more information.I changed the line to AllowOverride None again but the problem remains. The apache2 error.log does not contain any information. And Line 140 in the config file isIncludeOptional mods-enabled/*.loadas the error message indicates there is no libphp5.so in /usr/lib/apache2/modules just libphp5filter.so
Apache2 "configtest failed" when trying to restart
Please have a look at thisRewriteCondresource.RewriteCond %{REQUEST_FILENAME} !-f // ^ this means file. RewriteCond %{REQUEST_FILENAME} !-d // ^ this means NOT, "d" means directory. // Your rewrite rule here.
I'm trying to create a url handler by using php and .htaccess, my problem is that I don't know how to use rewrite condition only if the file\directory entered in the url does not exists.
RewriteRule only if directory or file does not exists
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^virtual-folder/(.*)$ folder/$1 [QSA] </IfModule>
Is it possible with Apache's RewriteEngine to do the following, and how?This is the environment:domain.comhas afolderthat contains aindex.htmlpage, htaccess is set to strip files sodomain.com/folder/opensdomain.com/folder/index.htmlNow what i need to achieve is displaydomain.com/folder/content (the index.html) as it comes fromdomain.com/virtualfolder/wherevirtualfolderdoes not exist and the url has to show asdomain.com/virtualfolder/I hope what i wrote it is understandable.Thank you very much
.htaccess folder to virtual-folder rewriting
you can remove .php from requests like soRewriteCond %{REQUEST_URI} ^/(.*).php$ RewriteRule ^(.*)$ %1 [L,QSA]
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed10 years ago.Improve this questionhtaccess to remove the .php extension of my site's files.RewriteEngine on RewriteBase / RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.*)$ $1.php [L,QSA]Now, if I go to my sitewww.mysite.com/homeworks fine, it redirects to home.php but the URL is still friendly.But if I write this URL:www.mysite.com/home.phpThe home.php is served, and the URL is not friendly.How can I avoid this behavior? I want that if the user writes www.mysite.com/home.php, the URL displayed in the URL bar be www.mysite.com/home
Remove .php extension (explicitly written) for friendly URL [closed]
Let's see if this works:RewriteEngine On # Check if the host name contains a . (localhost won't) # Check if the host name starts with www # Check if the host name ends with .com # Check if the connection is secure RewriteCond %{HTTP_HOST} \. RewriteCond %{HTTP_HOST} !=svn.myDomain.com RewriteCond %{HTTP_HOST} !^www [OR] RewriteCond %{HTTP_HOST} !\.com$ [OR] RewriteCond %{HTTPS} !=on RewriteRule ^.*$ https://www.myDomain.com/$0 [R=301,L]
I have the following bunch of domains:myDomain.demyDomain.commyDomain.co.zamyDomain.orgmyDomain.commyDomain.com.naWhat is the shortest way to write in the htaccess, to make ALL domains...Redirect tohttps://www.myDomain.com. I.e. Regardless of the domain that is entered, it will add www AND redirect to https, andStill work on my localmachine (so that if someone types inhttp://localhost/site/srcthat it won't redirect to the www sites?
HTACCESS RewriteCond without messing up localhost
First of all that code and comments look very familiar :)Use this code:RewriteEngine On RewriteBase / ## hide .php extension snippet # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1/ [R,L] # add a trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !/$ RewriteRule . %{REQUEST_URI}/ [L,R=301] # To internally forward /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*?)/?$ $1.php [L]
I'm trying to remove .php from my URLs and add a trailing slash to the end. I've got the .php removal working just fine, but I'm struggling to get the trailing slash working.Here's what I've got so far:# Turn mod_rewrite on RewriteEngine On RewriteBase / ## hide .php extension snippet # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L] # To internally forward /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*?)/?$ $1.php [L]Thanks in advance!
.htaccess remove .php and add trailing slash
More like a question forhttp://webmasters.stackexchange.comWell anyway, if you are using cPanel, you can do a wildcard redirect fromRedirectsunderDomainscategory.But if not, try this:Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^example.com[nc] RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
I have a wordpress instalation that is not redirecting urls not starting with www.Example:http://example.com/dir/doesn't send tohttp://www.example.com/dir/instead goes tohttp://example.com/How do I change the .htaccess below to always redirect to the page either using www or not?# BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] # uploaded files RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L] RewriteRule . index.php [L] # END WordPress
.htaccess permanent redirect to www
The three options are:1) Use a base tag (this will affect every relative URI on your page, including links, images, scripts, stylesheets and so on)<base href="http://yoursite/">2) Change all of your links to fully qualified URIs<a href="http://yoursite/yourpage.html">3) Use the "/" prefix to show that the path is relative to the root on each URI.<a href="/yourpage.html">I have personally used the base-tag option the most, which does get some bad press (from people that have used it without really understanding it). When it comes to mod_rewrite, the base tag is perfect as you probably DO want all your paths to be relative to the root, including all your images, css, scripts and links.
I have successfully created rewrite rules to handle URLs likehttp://example.com/xyzhttp://example.com/xyz/http://example.com/xyz/abchttp://example.com/xyz/abc/Here is the mod rewrite & regex:Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?([0-9]+)(?:\/)?$ /index.php?p=$1 [L] RewriteRule ^/?([-a-zA-Z0-9_+]+)(?:\/)?$ /index.php?n=$1 [L] RewriteRule ^/?([-a-zA-Z0-9_+]+)/([-a-zA-Z0-9_+]+)(?:\/)?$ /index.php?n=$2 [L]This works great, but the problem is that when I go tohttp://example.com/xyz/abc, my script gets the correct input (n=abc) but the paths are messed up, so all relative URLs in my code are broken, as they are now relative to xyz instead of the root.Is there a way around this at all? As you can see above I have tried to redirect to /index.php to force the path to be correct. My brain is fried after a long day of regex and code, so I hope it's not something disastrously trivial.
Mod Rewrite path issues
One way would be settingassets_base_urlsinapp/config.ymle.gframework: #.. templating: engines: ['twig'] assets_base_urls: http://your.site.com/web/
I've been working on this for quite a while to no avail.. I've got symfony installed on a shared web-host where I have zero access to change the DocumentRoot to the web/ folder so that is not an option to me...I've written my htaccessRewriteEngine On RewriteBase / RewriteRule ^$ web/app.php [QSA] RewriteRule ^(.*)$ web/app.php/$1 [QSA, L]I have also tried this withRewriteBase web/andRewriteBase /web/to no avail.With this, symfony is working.. I can login, I can do all of that... Only problem is, none of the assets are displaying... Chrome Developer Tools, is telling me it's finding a 404 which is right because it's not reading the /web/ folder as the DocumentRoot..So, how to fix this issue without re-writing files, or anything.. There's got to be a way to do this with .htaccess only...
symfony2 on shared hosting
The pattern of FilesMatch doesn't match against the query string, only the filename proper.You could, however, make use of mod_rewrite module, the%{QUERY_STRING}variable and theT flag:RewriteCond %{QUERY_STRING} dl RewriteRule .*\.mp4 - [T=application/octet-stream]Alternatively, if you have Apache > 2.3 (I think), you can use theIf directive, which is a lot cleaner:<FilesMatch "filepattern.mp4"> <If "%{QUERY_STRING} =~ /dl/"> ForceType application/octet-stream Header set Content-Disposition attachment </If> </FilesMatch>First solution was updated.
I wonder if it's possible with.htaccessto force files to download only if there is a specific GET variable, just like Dropbox does.Example:http://www.domain.com/file.mp4the server just serves the file, while:http://www.domain.com/file.mp4?dlforce the browser to download the file.PS: UsingPHPwithreadfile()it's not a viable option in my case. Thanks.
It's possible to force download with .htaccess and a specific GET request (Dropbox style)?
You can use this:RewriteRule ^browse/?$ index.php?file=browse&page=1 [L,NC,QSA] RewriteRule ^browse/([0-9]+)/?$ index.php?file=browse&page=$1 [L,NC,QSA] #else it's for files RewriteRule ^([a-z]+)/?$ index.php?file=$1 [L,NC,QSA]or use:RewriteRule ^([a-z]+)$ php.php?file=$1 [L,NC,QSA]the QSA (Query String Append) flag will allow passing _GET vars
Here what I've already done.RewriteRule ^([a-z]+)$ index.php?file=$1So when visitingdomain.com/browseit actually readsdomain.com/index.php?file=browseBut the problem is, this does not pass visible GET variables like this:domain.com/browse?page=2. How do I make it pass both GET variables:domain.com/index.php?file=browse&page=2.Any help would be appreciated!
.htaccess RewriteRule to work with hidden and visible GETs
First of all, make sure that the vhost in the apache configuration is properly configured and all subdomains of domain.com are in the same host configuration (wildcard):<VirtualHost *:80> ServerName domain.com ServerAlias *.domain.com ...You can get the redirect working with the following htaccess configuration:RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com RewriteRule ^(.*)$ http://domain.com/%1/$1 [L,NC,QSA]Now, if you open asd.domain.com it should redirect you to domain.com/asd. You will still have the problem, that the redirect is visible in the URL address bar. In order to prevent this, enable mod_proxy (and load the submodules) on your server and exchange the "L" flag with the "P" flag:RewriteEngine on RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com RewriteRule ^(.*)$ http://domain.com/%1/$1 [P,NC,QSA]If this doesn't work, viewing the vhost configuration and the content of error.log on subdomain calling will be helpful!References:.htaccess rewrite subdomain to directoryhttp://httpd.apache.org/docs/2.2/mod/mod_proxy.htmlhttp://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_p
I've read a lot of questions and answers about this on here but none that seem to solve my specific problem.I want to redirect any subdomain to the subdirectory to match.So: x.domain.com would go to domain.com/x, and y.domain.com would go to domain.com/y - But I want to do this without the URL in the address bar changing.Here's what I have so far:Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} !^(www)\. [NC] RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC] RewriteRule ^ /%1 [P,L]But this takes me to a website redirect loop, with an incorrect address in the URL bar where the subdomain still exists.For example, x.domain.com takes me to x.domain.com/x and I get a redirect loop error.I'd be grateful if anyone can point me in the right direction! Nothing I change seems to work...
Redirect wildcard subdomains to subdirectory, without changing URL in address bar
RewriteEngine on RewriteRule ^robots.txt - [L]Second line will exclude robots.txt from URL rewritting rules . Try above code
I have the following .htaccess file in my root:Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L] RewriteRule ^([^/]*)$ index.php?page=$1 [NC]This works as it should for shortening all my URLs to website.com/somethingThe problem is Google can't find myrobots.txtfile in my root. The above file isn't letting it through. when It type website.com/robots.txt I get a 404 not found. But if I comment out the above.htaccesscode I can get to it just fine.How can I edit my.htaccessfile to letrobots.txtthrough without interfering with my other URLs?
.htaccess not letting robot.txt through
I do something like this on sites that use 'seo-friendly' URLs.In .htaccess:Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* /index.php [L]Then on index.php:if ($_SERVER['REQUEST_URI']=="/home") { include ("home.php"); }The .htaccess rule tells it to load index.php if the file or directory asked for was not found. Then you just parse the request URI to decide what index.php should do.
I am designing my application. And I should make the next things. All GET parameters (?var=value) with help of mod_rewrite should be transform to the /var/value. How can I do this? I have only 1 .php file (index.php), because I am usign the FrontController pattern. Can you help me with this mod_rewrite rules?Sorry for my english. Thank you in advance.
PHP all GET parameters with mod_rewrite
what's the problem you're having now Seems like Richard got you what you needed?Using your example URL:http://www.domain.com/adm/generated/pass/6z9c4q9k8pand the following in your .htaccessRewriteRule ^adm/(.*)/(.*)/(.*)$ adm.php?mode=$1&generated=$2&pass=$3then you can do:$mode1 = $_GET['mode']; $generated = $_GET['generated']; $pass = $_GET['pass']; if ( $mode1 == 'generated' && $generated == 'pass' ) echo $pass;or was that not your question?
What way it is to be to get two GET methods in the URL by htaccess?RewriteRule ^adm/(.*)$ adm.php?mode=$1I've used that for the example URL:http://www.domain.com/adm/thismodeNow I want to get two methods like:http://www.domain.com/adm/thismode/othermodeI've tried this:RewriteRule ^adm/(.*)$/(.*)$ adm.php?mode=$1&othermode=$2But doesn't seem to work... how do I get it to do that?EDIT:$mode1 = $_GET['mode'];$mode2 = $_GET['othermode'];Like this...EDIT AGAIN:http://www.domain.com/adm/generated/pass/6z9c4q9k8pRight... this is the URL it has to doAnd in the PHP it has this:if($mode == "generated")I want the PHP to see if the mode is set in the URL and the generated password is the other GETI put the htaccess as this way:RewriteRule ^adm/(.*)/(.*)$ adm.php?mode=$1&generated=$2The PHP will also grab the generated password in the URL and display it on the page.
Getting two variables in the URL with htaccess
Just combine the two commands:scp -r web/* web/.htaccess[email protected]:site.com/If you want 0 entries of your password you can set uppublic key authenticationfor ssh/scp.
I am currently using the following command to upload my site content:scp -r web/*[email protected]:site.com/This works great except that the .htaccess file is not sent. Presumably, this is because it's hidden.I have tried adding a second line to send the file explicitely:scp -r web/.htaccess[email protected]:site.com/.htaccessThis works great except now I have to enter my password twice.Any thoughts on how to make this deploy with only 1 or 0 entries of my password?
How can I use `scp` to deploy a website's `.htaccess` file?
Replace in bootstrap fileindex.php$url->setBaseUri('/tutorial/');with$url->setBaseUri('/');
I'm having some trouble gettingPhalconTutorial 1 to work. In the end I've cloned the version of it onGithubto make sure I'm not missing something; still getting the same behavior from that.Pointing the browser to localhost/test as shown in the tutorial gives: `"PhalconException: TestController handler class cannot be loaded".Going tolocalhost/test.php, however, loads the "Hello!" test message correctly.Phalcon is shown inphpinfo() and get_loaded_extensions().I get this behaviour even having cloned the tutorial fromhttps://github.com/phalcon/tutorial.My guess is thatapacheis not re-writing URLs correctly, as described atPhalconphp routes not working, but my problem doesn't seem to the same as the one there.Contents of htaccess files:#/tutorial/.htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] </IfModule>and#/tutorial/public/.htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L] </IfModule>
Phalcon tutorial error PhalconException: TestController handler class cannot be loaded
You might have turned onregister_globalsin php.ini. Thats why you are getting variable with the name of array index (Here$_GET). It is not a best practice to turn onregister_globals.You can read morehere, why register_globals is bad.
I just wrote a htaccess file and a simple rule.RewriteRule ^/?([a-z]{2})/([0-9]{4})/?$ /run/run.php?country=$1&year=$2 [NC,L] This does http://www.localhost/us/2014On the php page, I accidently did:echo $country.' '.$year;This gave me the output below, which is correct.us 2014I did not do:$country = $_GET['country']; $year = $_GET['year'];But it still worked. Is this normal behaviour. Can I use this for the rest of the rules and the site? I'm using WAMP on Windows 7 Home Premium.
Is there no need to use $_GET['varName'] when using htaccess?
Take a look at your current .htaccess config. If might have the following lines:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]Those contain most of the URL rewriting that matters. The first three conditions say that all URLs will be rewritten except for existing files, directories and a request for /favicon.ico You can add your own favourite conditions there. For example, to avoid rewriting for urls of the form /gallery/.*:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteCond %{REQUEST_URI} !^/gallery/.*$ RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I am running a sitexyz.orgin Drupal.Now I want to install some other modules such asPHPBBforum andCopperminegallery. When I install these, and try to access the link xyz.org/gallery, it gives me drupal error."Page not found"What settings I need to change in order to let drupal know that/galleryis not a drupal node?
How to exclude a folder on Drupal site so that Drupal does not recognise it its own?
You can usemod_rewritefor this.RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule !^index\.html$ index.html [L,R=410]This rule will rewrite requests to non-existing files toindex.htmland send the 410 status code along with the response. But this requires Apache 2 asR=4xxis only available since Apache 2.
We have a client that is closing its doors. We want to redirect all traffic that goes to their domain to a new page index.html with a few images in the _img subdirectory. (The page explains what happened, what current customers can expect with their current orders, etc.)I've read about possibly using HTTP 410 Gone as the best way to technically explain to bots, etc. that the site is not there, isn't coming back and isn't providing a forwarding address. What would be the best way to do this in an .htaccess file, and direct users to the new index.html?
.htaccess to Redirect All Traffic to One Page (410 Gone)
Your HTTP to HTTPS redirect needs to go near the top of your.htaccessfile, immediately after theRewriteEnginedirective and, importantly,beforethe Laravelfront controller.As a general rule,external redirectsshould always go beforeinternal rewrites.The front controller catchesall requests(or rather requests that don't map to a physical file or directory) and rewrites these toindex.php(that ultimately handles the routeing). The problem is that your HTTP to HTTPS redirect occurs later and converts the now rewritten URL into an external redirect toindex.php.Likewise, your# Handle Authorization Headerblock should also go before thefront controller(ideally). (It will work in its current state, in per-directory.htaccessfiles, due to the looping nature of.htaccessfiles, but if you moved these directives to the server config it would fail.)
I have a Laravel 5.2 project. Recently, I installed an SSL certificate on my website so when I typehttps://example.comin the browser it works but when I writeexample.com, it connects by HTTP.To fix that, I added these lines to my.htaccessfile:RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]After that, when I typeexample.com, the browser redirects me tohttps://example.com. That's perfect.The problem is when I try to access the URLhttp://example.com/download/get/book/volume2, it doesn't redirect me to HTTPS. It redirects me to the index page. If I add thesofhttpsin the URL it works fine but I need the app to redirect me from HTTP to HTTPS.The route in routes file:Route::get('download/get/book/{book}'That route opens a PDF file that I have inprivates/storagefolder in the browser's tab.EDIT:My .htaccess file:<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # 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}] # require SSL RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect http to https in laravel 5.2
Spiele-Umsonst's answer didn't work for me (on Apache), but this did the trick:php_value default_charset Off AddDefaultCharset ISO-8859-1"Off" is a valid value for "AddDefaultCharset", so I guess for default_charset as well. "None" is not valid, so I guess that's why it didn't work. I think this might depend on some server configurations or the http deamon used.Further reading for Apache web server:http://httpd.apache.org/docs/current/mod/core.html#adddefaultcharset
My hosting service recently upgraded my website server from PHP 5.3 to 5.6 and it broke my site in that all my html/php files are ISO-8859-1 but the site is now being served up with response headers indicatingcharset=UTF-8I understand I should move to UTF-8 files eventually but in the meantime I want a quick-fix. I've tried the following fixes:<meta charset="ISO-8859-1"> (in the <head> tag of html files) AddDefaultCharset ISO-8859-1 (in .htaccess) default_charset= "ISO-8859-1" (in php.ini)...but none of these affected the response header charset.The only thing that worked in testing was adding this line to my header.php file used by most (not all) of my pages:header('Content-Type: charset=ISO-8859-1');But I don't want to hunt through all the straggler files and add that to each. I might as well convert all the files to UTF-8 if I'm going to hunt them and touch them in that way.So...I was wondering if anyone would know why my PHP.ini or htaccess fixes don't do the job universally? Does the fact that these are not working indicate that some other Apache setting is in control of the response header for charset?Thanks in advance.Update:I even tried addingaddCharset ISO-8859-1 .html .htm .phpto .htaccess but no joy.
PHP 5.6 Charset Header Back To ISO-8859-1?
You should follow this linkHow to restrict access to files in a folder in codeigniterAs post described, you need to deny all direct access to your files and read it through controller while user is logged in using authentication.
i had codeigniter project that contain the image folder and i want to make it unreachable from direct url access suppose some one enter urlhttp://localhost/project/images/Pricelistupdated.pdfthen it will be directly open in browser tab without login so i want to make it disable . when user login and click on download link only that time file will be download and open in new tab . either it can not open when anyone enter direct url in browser i used followingRewriteEngine on RewriteCond %{HTTP_REFERER} !^http://(www\.)?projects/project/ [NC] RewriteCond %{HTTP_REFERER} !^http://(www\.)?projects/project/.*$ [NC] RewriteRule \.(pdf|PDF|jpg|png|gif|PNG)$ - [F]but this code also disable the download and open in new tab functionality
How can i restrict the image Folder using .htaccess in codeigniter
You have to use Rewrite base in three .htaccess files. The one in the root directory which contain directories app , lib , plugin and vendor should look like<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>The app / htaccess should look like<IfModule mod_rewrite.c> RewriteEngine on RewriteBase /app/ RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L] </IfModule>And finally the app/webroot/htaccess should look like<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /app/webroot RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] </IfModule>If your lib is not in the root folder you will have to also the change the values in core.php to map it to relevant address. For that you can check out the advanced installation in the cook book.
I am having an issue with the .htaccess file on a justhost.com account. I recieve constant internal 500 errors and I have tried many different solutions around the web. Here is what my htaccess files look like:ROOT HTACCESS<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>app/ HTACCESS<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L] </IfModule>app/webroot/ HTACCESS<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] </IfModule>The issue is that I get this in the error log: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.Ive tried setting the RewriteBase to / but it doesnt correct the issue.
htaccess with cakephp on justhost account 500 error
This will redirect everything from olddomain.com to newdomain.com:RewriteEngine on RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,QSA,L]You can put that mod_rewrite code into your olddomain's .htaccess.
I have a small dilemma.I have been working on a project for almost a year now and had an old domain name. Not knowing how Google has indexed the whole site under the old domain which has worried me. I want to put the site up on my new domain name and I think doing a 301 is the way forward. I will need to do this on every dynamic page. The good thing is the page structure is identical.Any advice on the best way to do this would be massively appreciated.
htaccess 301 redirect url
More generally you can whitelist all resources withpagespeedin the name with:RewriteCond %{REQUEST_URI} !pagespeedSee thenew section in the mod_pagespeed FAQ
I have the following in my .htaccess file:# Allow any files or directories that exist to be displayed directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Rewrite all other URLs to index.php/URL RewriteRule .* index.php/$0 [PT]The server admin has installed Google mod_pagespeed and of course, because the folder doesn't exist, it logs an error every time as it tries to access/mod_pagespeed_beacon(and no stats are logged).WhatRewriteConddo I need to add (and where) so/mod_pagespeed_beaconwill work?
mod_rewrite mod_pagespeed RewriteCond
cd to a folder before the folders that store the htaccess$find . -name ".htaccess" -exec grep -r -n -H -I 'string' {} \;
How can I grep for a certain string recursively in all .htaccess files?grep -r -n -H -I 'string' .htaccessdoesn't seem to work.I'm on a GNU Linux system.
Grep a string recursively in all .htaccess files
First you need to create the htpasswd file in your home directory using thehtpasswdcommand. SSH into your directory and enter:htpasswd -c .htpasswd useroneEnter password foruseronetwice.For multiple users, repeat the command without the-chtpasswd .htpasswd membertwoThats all.
I have protected my website with .htaccess file with one user, script that i use in below.htaccess :ErrorDocument 401 "Unauthorized Access" RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] AuthType Basic AuthName "domain-name.com" AuthUserFile "/home/path/.htpasswds/domain-name/passwd" require valid-userpasswd :user1:password1How to add multiple users? I have tried as below and not success.user1:password1 user2:password2Please assist me in this, thanks in advance
add multiple users for .htaccess
To return404 not foundfor any request that is causing 403 today you can do:ErrorDocument 403 /404.phpAnd then in/404.phpyou can add this line to return 404 status to clients:<?php # your custom 404 content goes here # now make it return 404 status to browser http_response_code(404); ?>To return 404 for all the requests to directories you can do:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ - [L,R=404]
I need to redirect all requests on an Apache 2.2 server for any directory that gives a 403 to a 404 not found.Ex:/xyzor/xyz/throws a 403 -> redirect to 404/xyz/sometext.txtreturns normally.Looking around, I came across this post:Problem redirecting 403 Forbidden to 404 Not FoundRedirectMatch 404 ^/include(/?|/.*)$ /include 404 (instead of 403) /include/ 404 /include/config.inc 404 (instead of 403)However, the last case for that also returns a 404. Also, it only affects /include/ directory, I was looking more for any forbidden directory. So far I have:RedirectMatch 404 ^[\/[\w+]]+\/$Anyone have an idea of how to accomplish this? Thanks,
Redirect all Apache 2.2 403 Forbidden to 404 Not Found
This code is Prepend the filephp_value auto_prepend_file "/dir/path/utilities.php"This code is Append file to bottom of the pagephp_value auto_append_file "/dir/path/templates/footer.php"I found this answer inhttp://samweby.blogspot.in/2013/07/prepend-and-append-htaccess-file.htmllink.
How to include php file using .htaccess? I google it but i cant find a good tutorial or code.Here is a php include code :<?php require('footer.php'); ?>
How to include php file in .htaccess?
Enable the rewrite module in apache by command on ( for Ubuntu )sudo a2enmod rewrite
I have only a single line in the .htaccess file:RewriteEngine OnTaking that line out makes the error go away. I've checked as many places as I know of for the AllowOverride rule (but I know next to nothing about how that works) and I thiiiiink it's set correctly, but I don't know for sure.I can't figure out what's going on and I'm not sure what to even check. Any ideas? Thanks in advance.
.htaccess causing 500 error
You need to change your RewriteRule to include the new domain you're trying to redirect too, otherwise it will treat the beginning/as a new path on the current domain.RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com RewriteRule ^(.*)$ http://domain.com/subfolder/$1 [R=301]Should do the trick.
I need help redirecting a subdomain to a subfolder on my website using the .htaccess file. I am not a pro in regards to configuring the .htaccess file, so please forgive me if my problem is a simple fix.In my .htaccess file, I have the following code:RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com RewriteRule ^(.*)$ /subfolder/$1 [R=301]It almost works, but when I entersubdomain.domain.cominto the address bar, I get redirected tosubdomain.domain.com/subfolder/This is really close, but I don't want the preceding subdomain in the redirected URL, I want the redirection to go todomain.com/subfolder/
How to redirect from a subdomain to a subfolder using .htaccess
I have previously faced same issue and I solved by adding this line at the top of my.htaccessthat is at the root directorySetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
This is my.htaccessfile:RewriteEngine on RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.phpEven though I have added below line to my.htaccessfile I cannot access$_SERVER['HTTP_AUTHORIZATION'].RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]When I'm doingprint_r($_SERVER)I can't findHTTP_AUTHORIZATION. I have googled for an answer but none of them worked.
$_SERVER['HTTP_AUTHORIZATION'] is missing
Create a .htaccess file and put the following line in it:ErrorDocument 404 /errorpageFileName.phpThat will set the page 'errorpageFileName.php to your error 404 page. You can of course change the file name to your likings.You can read more in-depth about it here:Custom 404 error issues with Apache
I am a novice in PHP, I hope you can help me with this problem. How can I create a custom 404 error page in PHP without going anywhere or redirect it to other page.Ex.mysite.com/no-whereThe pageno-wheredoes not exists. I want to display a 404 error message with design on that URL.How can I get the current URL? I got an error on this. Coz I want to check the header if its 404.$url = $_SERVER['REQUEST_URI']; $array = get_headers($url); $string = $array[0]; if(strpos($string,"200")) { echo 'url exists'; } else { echo 'url does not exist'; }
Custom 404 Error Page in PHP
You should let wordpress write this file for your localhost server.You cannot simply copy.htaccessfrom another server and expect it will work, you have to modify it to reflect your server conf.You should modifyRewriteBaseand the lastRewriteRule, e.g. forhttp://localhost/wordpress:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L] </IfModule>
I was trying to usepermalink featureofWordPresson mylocalhostso I just made copy the code which wasgenerated by WordPresswhen I clicked onpost name from Common Settings. I saved that generated code in my localhost where thewordpress index.phpfile was stored in the name of.htaccessand now when I am going to visit the page, url bar of thebrowser is showing the full address of the postbut thepost can not be seen on the browser.Only the404 Not Found error is comming. Can someone tell me what is the wrong part here?
changing the .htaccess file in wordpress
Try:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?mysite/(.*)$ /mysite/index.php/$1 [L]
I am newbie to Yii framework. I have uncommented the url manager in the config file and got a url scheme like this:http://localhost/mysite/index.php/displayAllI don't want the index.php in the url. So I want a url some thing like thishttp://localhost/mysite/displayAllTo accomplish this, what should I do. I did play with the url manager and some htaccess, but nothing gone well.Please help
Yii how to get clean and pretty URL
First of all, there's theOfficial Documentation. To solve your specific problem, I would go about this way:RewriteEngine on #Turn on rewrite RewriteCond %{REQUEST_FILENAME} !-f #If requested is not a filename... RewriteCond %{REQUEST_FILENAME} !-d #And not a directory RewriteRule ^([^/]+)/?$ /$1.html [L] #Preform this redirectTheRewriteConds only apply to the next following rule. If you were to have multiple rules, you'd need to write the conditions for each one.Now, the Apache server matches the requested path (everything after www.example.com/), to see if it matches any of the rules you've specified. In which case, there is only one:^([^/]+)$This regular expression matches any number of characters, which are not slash/, followed by an optional trailing slash. If the match was found, it will rewrite the request to the second parameter:/$1.html,$1means "Whatever was matched between the brackets", which in our case is all of the non-slash characters.The[L]flag, tells the rewriting engine to stop looking for rules if this rule was matched.So to conclude,www.example.com/whatever/will be rewritten sliently at the server towww.example.com/whatever.html
I'm trying to make my website display the other pages as a www.example.com/pageone/ link instead of www.example.com/pageone.html.Problem is, i'm reading up on ways to do that using .htaccess and its getting me confused because i don't understand the commands.I understand that the first step, however, is to write this in the .htaccess file:RewriteEngine OnAfter this step, i have absolutely no idea whats !-d nor {REQUEST_FILENAME} nor ^(.*) and all that programming text. Is there a documentation that i can refer to?Or can anyone provide me a simple explanation on how to configure the .htaccess file to understand that if i want to go towww.example.com/pageone.html, all i need to type into the URL iswww.example.com/pageone/and PHP files, etc as well?
How does .htaccess work?
Add aRewriteConddirective, which defines the conditions for thefollowingRewriteRule.So for example:RewriteCond %{HTTP_HOST} ^mydomain\.com RewriteRule ^([0-9]+)/?$ project.php?id=$1 [NC,L] # Handle project requests RewriteCond %{HTTP_HOST} ^mydomain\.cz RewriteRule ^([0-9]+)/?$ project_cz.php?id=$1 [NC,L] # Handle project requests
As a bit of background, we have two domains:mydomain.commydomain.czmydomain.czpoints tomydomain.com's server and uses the same directory. We have a RewriteRule in .htaccess (which both domains share) as follows:RewriteRule ^([0-9]+)/?$ project.php?id=$1 [NC,L] # Handle project requests RewriteRule ^([0-9]+)/?$ project_cz.php?id=$1 [NC,L] # Handle project requestsThis RewriteRule showsmydomain.com/1while using content frommydomain.com/project.php?id=1(for example) andmydomain.cz/1also pullsmydomain.com/project.php?id=1for content. However, I would like anymydomain.cz/(insert id here)'sto pull content fromproject_cz.php?id=(insert id here)rather than displaying the server's domain, mydomain.com - any ideas?For example:mydomain.cz/1would usemydomain.com/project_cz.php?id=1andmydomain.com/1would usemydomain.com/project.php?id=1Many thanks.
.htaccess RewriteRule: two domains using same server and directory
The parts of the rewrite rule break down as follows:RewriteRuleIndicates this line will be a rewrite rule, as opposed to a rewrite condition or one of the other rewrite engine directives^(.*)$Matches all characters(.*)from the beggining^to the end$of the request/index.php/$1The request will be re-written with the data matched by(.*)in the previous example being substituted for$1.[L]This tells mod_rewrite that if the pattern in step 2 matches, apply this rule as the "Last" rule, and don't apply anymore.Themod_rewrite documentationis really comprehensive, but admittedly a lot to wade through to decode such a simple example.The net effect is that all requests will be routed throughindex.php, a pattern seen in many model-view-controller implementations for PHP.index.phpcan examine the requested URL segments (and potentially whether the request was made via GET or POST) and use this information to dynamically invoke a certain script, without the location of that script having to match the directory structure implied by the request URI.For example,/users/john/files/indexmight invoke the functionindex('john')in a file calleduser_files.phpstored in a scripts directory. Without mod_rewrite, the more traditional URL would probably use an arguably less readable query string and invoke the file directly:/user_files.php?action=index&user=john.
Could anyone explain the following line please?RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule in htaccess
RewriteCond %{HTTP_HOST} ^(?:www\.)?site\.com$
I have following .htaccess to point a domain to a subfolder.RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} site.com RewriteCond %{REQUEST_URI} !folder_site/ RewriteRule ^(.*)$ folder_site/$1 [L]How can I changeRewriteCond %{HTTP_HOST} site.comto also includewwwas an optional match.
Making www optional in htaccess rule
Create an file with php extension and include it in your website as javascript.map.api.js<?php header("Content-type: application/javascript"); //my php here ?> //my javascript hereIn your HTML File:<script type="text/javascript" src="map.api.php"></script>If you wan't to hide the php extension, you can work with mod_rewrite (Apache):RewriteEngine on RewriteRule ^map.api.js$ map.api.php
So I'm trying to use PHP in a .js file, here's what I have so far..htaccess(any *.api.js will be processed as PHP)<FilesMatch "^.*?api.*?$"> SetHandler php54-script </FilesMatch>map.api.js<?php header("Content-type: application/javascript"); //my php here ?> //my javascript here.php files all include<script type="text/javascript" src="map.api.js"></script>For some reason this isn't working, and after much research I can't find a solution.In the chrome developer tools I get an error,Uncaught SyntaxError: Unexpected token <- pretty self explanatory, it isn't expecting<?phpat the top of themap.api.jsfile.Anyone else here tried using PHP in a .js file before? If there is a better solution I'd like to know as I can't find much on Google.
Using PHP in .JS file?
I have changed the .htaccess files as below and its worked out, Google Chrome is not accepting the '*', so I specified the exact URLHeader set Access-Control-Allow-Origin "http://localhost:8100" Header set Access-Control-Allow-Credentials: true
I have setup the Ionic development environment using Yeoman generator (https://github.com/diegonetto/generator-ionic). Everything is works well.The problem is on Sever side request, I am getting the Cross-Origin Request Blocked error.I add below link in .htaccess file and AngularJS app.js, still getting same errorHeader set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Headers: AuthorizationAngularJS Provider$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; $httpProvider.defaults.withCredentials = true;Error Message I am getting isCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://192.168.1.18/tracker/user/login. This can be fixed by moving the resource to the same domain or enabling CORS.Screen of Request & Response HeaderPlease guide me any configuration need to be changed for enabling CORS. Our server side framework is Zend 1.x
Ionic - Cross-Origin Request Blocked Issue
I have found the answer. Its working. the code is as follows to rewrite and redirect the urlOptions +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / ## hide .php extension # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L,NC] ## To internally redirect /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_FILENAME}.php [L]It rewrites and redirects the URL. Thanks all for ur answers.
the following code is not working to remove the file extension .phpOptions +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.+)$ $1.php [L,QSA]my url not changing fromexample/about.phptoexample.com/about
remove file extension htaccess not working
I know this is an old question but I've been doing something similar just by adding something along the lines ofRewriteBase /flight/in the .htaccess file (before all of your rules) of the flight directory. Hope this helps someone else looking for the same thing. Example:RewriteEngine On RewriteBase /flight/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [QSA,L]
So I'm using the Flight PHP microframework (http://flightphp.com/) to do routing. My question is, how can I run the router from within a subdirectory? What I mean is, essentially, run it 'sandboxed' within a folder.As in, a request to '/' just pulls the regular index.php file. But a request to '/flight/file' would load the URL using Flight.I know you can't just dump it in a folder on the server and expect it to work because FlightPHP expects the URLs relative to the root.Is there a way to run FlightPHP isolated in a directory with the rest of the website running regular PHP?EDITI tried simply putting the .htaccess file into the subdirectory. This has the peculiar effect of causing the routes to still act as if they are from the root (e.g. /thing/otherthing/ when it should be /otherdirectory/thing/otherthing/ ) while simultaneously causing the 404 callback to not work. Not what I intended.EDIT 2Contents of .htaccess file, which are what is suggested by the Flightphp website:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [QSA,L]
Flight PHP Routing from Subdirectory
For a full website redirection, you can use this (entire) .htaccess :RewriteEngine On RewriteBase / RewriteRule ^(.*)$ http://againstcancer.nl/$1 [R=301,L]EDITFor two domains running side by side, with one redirecting the other :# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} racentegenkanker\.com$ RewriteRule ^(.*)$ http://againstcancer.nl/$1 [R=301,L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
I want to redirect all the pages of my website to a new domain with a redirect. I've managed to get it working on domain level but not on the subpages.So olddomain.com redirects to newdomain.com but olddomain.com/contact doesn't redirect to newdomain.com. It still shows the old domain.I've used multiple rewrites rules but none of them seem to works. Any help is much appreciated.This is the code that I'm using right now in my .htaccess file# 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 WordPress RewriteCond %{HTTP_HOST} ^racentegenkanker\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.racentegenkanker\.com$ RewriteRule ^(.*)$ "http\:\/\/againstcancer\.nl\/$1" [R=301,L]
Redirect all pages to new domain
For a quick way to handleFront-end Controllerswith Apache, useFallbackResourceand parse the URL with PHP.FallbackResource /index.php
I am trying to create a nice url structure for my site.My router class will only work if the url is in the style of ?something=value.How do I get it so it will work like:/something/valueIn my .htaccess I have:Options FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule !\.(js|txt|gif|jpg|png)$ index.php?$1 [L,QSA]And in my router class I'm making:class init { function __construct() { $URL = substr($_SERVER['REQUEST_URI'], 19) ; $URLElements = explode('/', $URL) ; // Adjust if needed. $class = $URLElements[0] ; $method = $URLElements[1] ; if(($t = substr_count($URL, '/')) > 1) { for($i=2;$i<$t+1;$i++) { echo $URLElements[$i].'<br />'; } } }}Thanks to Jason, my .htaccess is now just:FallbackResource /t2013/public_html/index.php
Routing URL Path with PHP and Apache
Try putting this in your .htaccess:RewriteEngine on RewriteRule ^blog/(.+) error/index.php [L,R]ReplaceRwithR=301if you want a 301 redirect, and get rid ofRentirely if you don't want an external redirect.
I want to redirectallpages from the.com/blogdirectory to the.com/errordirectory.I have searched the web, and found loads of different ways of doing it, but I want it to redirect to asinglepage.All the things I have tried redirect to the same file name, but in different directory. For example,.com/blog/index.nonexistingredirects to.com/error/index.nonexisting.I would like all files in the first directory to redirect to a certain file, so if you go to.com/blog/whatever.phpit would go to.com/error/index.php, and if you go to.com/blog/random.xmlyou would be redirected to.com/error/index.php.Is there any way to do this?
.htaccess redirect directory to a single page
You need three things:Inside<Directory>, allow .htaccess files withAllowOverride All.Give the required permissions of mod_rewrite withOptions FollowSymLinks.Inside the .htaccess, includeRewriteBase /test/.
I have this alias configuration:Alias /test/ "D:/WWW/Test/" <Directory "D:/WWW/Test/"> Order allow,deny Allow from all </Directory>Then insideD:/WWW/Test/directory, I put .htaccess with the following configuration:<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^([^.]*\.css)$ resources/$1 [L,NC] </IfModule>I just want to redirect all request fromlocalhost/test/css/*tolocalhost/test/resources/css/*.But it seems that the.htaccessis ignored. Even if I putDirectoryIndex blablabla.php, browser still displays index.html.How to solve this? Thank you.
Apache : How to Use Rewrite Engine Inside Alias
Try to change the timezone in thephp.iniconfiguration file, and then restart the apache service. You should havephp.inisomewhere inside your WAMP installation folder.EDIT:You might have the php.ini file inside the folder:/wamp/bin/php/phpX.X.Xwhere phpX.X.X is your php version.Look for the "date.timezone" line and change it to something like this:date.timezone = "America/Los_Angeles"You can find the supported timezones here:http://www.php.net/manual/en/timezones.phpMore technical information is available here:http://php.net/manual/en/datetime.configuration.phpThe .htaccess file has a local range, normally to the folder and sub-folders where the file is created. Changing the php.ini file makes the changes global to your PHP installation.
I am using WAMP server running PHP. At a particular step I am trying to capture system time and add it to the database with the following query$strSQLInsert = "UPDATE track SET State = 'Repeat' , DateTime = '" . date("m/d/Y h:i:s a") . "', where AccID like '". $values['SampleID'] ;but the time stamp is way off than my system time. The date is okay. I googled and found out that I can update my .htaccess with this lineSetEnv TZ America/Los_AnglesBut I couldn't find where htaccess is. How do I get the correct time stamp.
Apache time stamp incorrect
Try adding this condition:RewriteCond %{REQUEST_FILENAME} !-fThis should allow any files that actually exist (there are other options for other types of files). This assumes it wouldn't mess up anything else for other files that already exist.
My site is set up with htaccess directing all pages from html to php as below:RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^website.com RewriteRule (.*) http://www.website.com/$1 [R=301,L] RewriteRule ^(.+)\.html$ http://www.website.com/$1.php [R=301,L]I am trying to set up Yahoo Site Explorer and to verify my account I need to either add a meta tag or add a html file to my website root folder. Yahoo is refusing to recognize my meta tag (I am sure I have added it correctly)! So my only option is to add the html file.My html file keeps getting redirected to php and it seems yahoo cannot find it.Is there something I can add to my htaccess file so that all files are redirected to php apart from the one file yahoo needs to see?
htaccess redirect all but one page from html to php
Use Base URL, for example:-<html> <head> <base href="http://www.w3fools.com/" target="_blank" /> <!-- only one base element is allowed --> <link rel="stylesheet" type="text/css" href="/stdtheme.css" /> </head> <body> <img src="stickman.gif" width="24" height="39" /> - Notice that we have only specified a relative address for the image. Since we have specified a base URL in the head section, the browser will look for the image at "http://www.w3schools.com/images/stickman.gif" <br /><br /> <a href="http://www.w3fools.com">Don't use W3Schools</a> - Notice that the link opens in a new window, even if it has no target="_blank" attribute. This is because the target attribute of the base element is set to "_blank". </body> </html>
I wonder if this is possible to tell via .htaccess or any other manners to set a base URL.ExampleMy CSS in the index.php is set like this<link rel="stylesheet" href="css/style.css"/>Everything works fine when i'm on the first directory to load my file and pages. But when I have a page set in a folder like /page/index.html. The css isn't loaded because the folder is not in page/ but in the root directory.So is that possible to tell it to look always from the root directory to load the CSS, images, javascript, etc or I have to set the full url path to each element I want to load (CSS, images, javascript, etc)?Thanks
Base URL in .htaccess
For #1:Set theAuthinstructionsonly on the VirtualHost which is listening on*:443. You should have 2 VirtualHosts, one listening on port 80 and one on port 443. UsingAuthType Basicon non-SSL communication is a big issue, username and password are just base64 encoded, so it's inclearon every requests (even images or css) that are used on your http server!
I've read some posts on how to redirect to SSL, also some on how to make sure a site is using the www subdomain / canonical name, and some on how to set up Basic Auth. Here is what I have in my .htaccess file right now:RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteEngine on RewriteCond %{HTTP_HOST} !(^www\.site\.com*)$ RewriteRule (.*) https://www.site.com$1 [R=301,L] AuthName "Locked" AuthUserFile "/home/.htpasswd" AuthType Basic require valid-userIt works fairly well, but I'd like to optimize it. My questions include:How do I avoid double authentication? When I access the site w.o. SSL I have to authenticate, and then I am redirected to SSL and have to authenticate again. Can I just be redirected and then authenticated?It looks like the first rule is pretty awesome because I could use it on any site without modifying it. Can rule #2 be rewritten to be site-independent? ie: it will force www to be used on any site no matter what the domain name is (with a better written rule)?answered hereHow would I do the reverse of number 3 with a rule that would work on any site to force the site not to use www, ie redirect to site.com from www.site.com?answered here
Force SSL on Apache, with Auth and Canonical redirect
Don't add the rewrite rule to your.htaccessfile. WordPress manages that file for you, so try to use built-in features whenever you can.WordPress actually has a somewhat advancedrewrite enginethat ships standard - and it's pluggable just like the rest of the platform.The trick, though, is working with it. You'll need to register your RegEx so WordPress knows what kinds of strings to match (i.edynamic/location/(.*)/code/(.*)=>/dynamic?$loc=$1&code=$2). Then you'll need to set up the page and script on the back end to handle the submission.For a similar example, look at the answer I received to parsing custom URLs with a custom post type over onWordPress Answers. Extending this, you'll need to set up code similar to the following (note:untested!!!):<?php add_action('init', 'add_my_rewrite'); function add_my_rewrite() { global $wp_rewrite; $wp_rewrite->add_rule('location/([^/]+)/code/([^/]+)','index.php?loc=$matches[1]&code=$matches[2]','top'); $wp_rewrite->flush_rules(false); // This should really be done in a plugin activation }Thisshouldadd the rewrite structure to your.htaccessfile automatically.
I have a perfectly good (so far) setup of wordpress of for a new website. The pretty urls are working as expected.I have 1 dynamic page that loads content depending on the querystring:/dynamic/?loc=england&code=ukI wish to make this URL "pretty" as well but every-time I modify the .htaccess no changes are made. Tried everything and googled everything else - last resort. If I could get the following to work then I would be happy.I need to make the URL look like./dynamic/location/england/code/uk/Adding this to any .htaccess breaks the whole website.RewriteRule /dynamic/(.*)/(.*)/(.*)/(.*)/$ /dynamic?$1=$2&$3=$4What am i missing.Thanks in advanceN
Wordpress custom Querystrings & Pretty URL's - How?
You can do this with one VirtualHost for all of the subdomains:<VirtualHost *:80> ServerName category.domain.com ServerAlias foo.domain.com bar.domain.com RewriteEngine On RewriteCond %{HTTP_HOST} (.*).domain.com RewriteRule (.*) http://domain.com/%1$1 [R=301,QSA,L] </VirtualHost>For it to work properly, you must have something set as the ServerName, so just choose one and list the rest of your subdomains on the ServerAlias line.You can have multiple ServerAlias lines, so you could break them into multiple lines for readability if you have a large number of subdomains.In the RewriteRule, the %1 matches the first matched pattern in preceding RewriteCond lines.
I need to redirect every subdomain into the domain it belongs changing the subdomain name into a parameter using mod_rewrite, and I'm not sure how. Also, I need to "reindex" the parameters so that the subdomain name becames the first parameter of the uri and the other parameters of the uri follow it by their own order. Something like thiscategory.domain.com/search/flowerstodomain.com/category/search/flowersAny thoughts on how to achieve this using mod_rewrite?Cheers!
apache - redirect subdomain to another domain
When URLs are rewritten, the client doesn't know it. So when a client looks at a page at the URL "example.com/some/url/" and the page references an image in "images/image.jpg", the client looks for the image in "example.com/some/url/images/image.jpg" even though the page actually resides in "example.com/some/other/url/". That's the problem you're facing, right?There are three main solutions to this problem:Use absolute paths to resources instead of relative ones.Use the<base>tag to ensure that the client knows the root upon which to build its relative URLs is different from the page's apparent URL.Add a new rule for "some/url/images/" in your rewrite rules.Option 1 is probably the best idea, and you'll find that most sites that use URL rewriting use it, including Stack Overflow itself. Option 2 is frowned upon, but works and is relatively easy. Option 3 is the most difficult to maintain, as URL rewriting exceptions and special cases can appear as you're defining new rules.The most maintainable solution is to use absolute URLs.
So I rewrote my paths to something like:URL/really/nice/paths/using mod_rewrite rules like this:<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 [PT,L] </IfModule>The question is how could I rewrite the paths for js/css/image files too, so when they are requestedwith a relative pathfromURL/really/nice/path/to be served fromURL/scripts/,URL/styles/andURL/images/folders instead? Can this be done without usingRewriteBase?
Rewrite css/js paths
In aFilesdirective, you can not match against file path, you can match againstfilename.extonly<Files "serviceworker.js"> Header Set Service-Worker-allowed "/" </Files>Put this in an .htaccess file in the appropriate subdirectory, to restrict it to this path only, e.g./path/to/wp-content/themes/stefanklokgieters/.htaccess
I am trying to set a header for a specific file via my htaccess file in order to give my service worker access to my root. Unfortunately I don't see the header appearing... Perhaps I am not targeting the file (https://www.stefanklokgieters.nl/wp-content/themes/stefanklokgieters/serviceworker.js) correctly?# Add custom header to single file <Files "/wp-content/themes/stefanklokgieters/serviceworker.js"> Header set Service-Worker-Allowed "/" </Files> # 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 WordPressMany thanks in advance!Cheers, Stefan
Custom HTTP Header for a specific file
You must use the full path to your .htpasswd file.Create a .php file in the same folder, containing the following code :<?php echo dirname(__FILE__) . '/.htpasswd'; ?>Then access it via your browser and it should display the full path you'll need to put in your .htaccess file.
My .htpasswd file is in 'www' folder in wamp. My .htaccess file is also in same 'www' folder.I want to set path for .htpasswd in .htaccess file. How to set path in AuthUserFileAuthName "Restricted Area" AuthType Basic AuthUserFile www/.htpasswd **path incorrect AuthGroupFile /dev/null require valid-user
.htpasswd path in .htaccess file
Yes, you can do that from create a.htaccessfile in your laravel root directory.and put below code in that file.<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] </IfModule>It should be redirected easily.Another way to remove public folderfor more reference click here....
I want to host my Laravel 4 project on free webhosting. To work, the hosting root dir must point to the "public" folder of my project where is taking place the .htaccess file. I did not succeed with finding free hosting which allows changing the root dir so I tried to place another .htaccess file in the main project dir which redirects to the public folder. Then the landing page opens but non of the routes in routes.php works. So my question is:Is it possible to put the .htaccess file from "public" to the main dir and the application to work properly ?Hope my question was clear.
Laravel htaccess in root directory
This should work:# Disable the directory processing, Apache 2.4 DirectoryIndex disabled xxx RewriteEngine On # Serve existing files RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] # For / serve index.html if it exists RewriteCond %{DOCUMENT_ROOT}/index.html -f [NC] RewriteRule ^/?$ index.html [L] # Otherwise use front controller RewriteRule ^ app.php [L]Remember thatRewriteCondwith-for-dneeds full path to the file or directory that's why you need to prefix the filename with%{DOCUMENT_ROOT}/. No need to escape dots here.
Such a simple problem but htaccess and I have never got along.Serve the file if it exists.If the URI is just / and if index.html exists then serve index.htmlOtherwise serve app.phpHere is .htaccess:# Disable the directory processing, Apache 2.4 DirectoryIndex disabled xxx RewriteEngine On # Serve existing files RewriteCond %{REQUEST_FILENAME} -f RewriteRule .? - [L] # For / serve index.html if it exists RewriteCond %{REQUEST_URI} ^/$ RewriteCond index.html -f RewriteRule .? index.html [L] # Otherwise use front controller RewriteRule .? app.php [L]It works if I comment out the RewriteCond index.html -f line as long as index.html does in fact exists. But I also want to check for index.php so I need the file exists check. And if nothing else I'd like to understand why the posted lines do not work.
RewriteCond file exists
You are getting a 404 page because WordPress internally doesn't understand how to handle the URL. So the solution you are looking for will be a combination of .htaccess (for the redirection) plus a rewrite rule so that WordPress can handle the URLAdd the following to functions.phpadd_action( 'init', 'init_custom_rewrite' ); function init_custom_rewrite() { add_rewrite_rule( '^phones/compare/([^/]*)/?', 'index.php?page_id=XXX&between=$matches[1]', 'top' ); }ReplaceXXXwith the page_id of compare page, flush the rewrite rules by re-saving your permalink structure. Now add a rule to .htaccess for the redirection and that should work.EDITAdd the following code to functions.php to accessbetweenquery var in the pageadd_filter('query_vars', 'my_query_vars', 10, 1); function my_query_vars($vars) { $vars[] = 'between'; return $vars; }And you can then access it usingget_query_var("between")
I have a WordPress site with a custom page comparison that gets a string.Now it takes:mysite.com/phones/compare/?between=samsung-galaxy-note-3-vs-nokia-lumia-730It needs to be like that:mysite.com/phones/compare/samsung-galaxy-note-3-vs-nokia-lumia-730I've tried adding code on my site's .htaccess that didn't worked for me and went to WordPress 404 page:RewriteRule ^phones/compare/(.+?)/?$ phones/compare/?between=$1 [NC,L]Also I need to redirect to the new search engine friendly URL too when user gets to mysite.com/phones/compare/?between= URL.
URL Rewrite on a WordPress Page Query String
+50Its the beauty of symfony that it is highly configurable. You can achieve what you are looking for by following the simple 4 steps:Create a directory(say project) and put all the content ofsymfonysitethere. You can put this directory any where you like. For simplicity we are going to create the directory in yoursymfonysitedir.Move all content of yoursymfonysite/webtosymfonysiteEdit theapp.phpand orapp_dev.phpto modify two line as follow:$loader = require_once __DIR__.'/../app/bootstrap.php.cache';require_once __DIR__.'/../app/AppKernel.php';to$loader = require_once __DIR__.'/project/app/bootstrap.php.cache';require_once __DIR__.'/project/app/AppKernel.php';Editcomposer.jsonfile to update the value of"symfony-web-dir": "web"and change it to"symfony-web-dir": "../",Your modified directory structure may look like:/srv /www /site.com /symfonysite /project /Other Drupal hosted site filesNB: For security reason symfony suggest to expose only the web directory to a web accessible path. You can put the project directory any where you like. Just need to update the path as per your locations. To give this set-up a little more security you can put a .htaccess file in the project directory.htaccessDeny from allEnjoy!!
My server has the following directory structure/srv /www /site.com /symfonysite /Other Drupal hosted site fileswhen I go tosite.commy drupal site opens up and I want to be able to access my symfony site onsite.com/symfonysiteinstead ofsite.com/symfonysite/web/app.phpI created an.htaccessfile inside/symfonysiteshown below<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /billing/web RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php [QSA,L] </IfModule>But this only gets rid of the app.php part, i.e.site.com/symfonysite/webopens my symfony site andsite.com/symfonysitegivesNo route found for "GET /symfonysite/"error.What am I doing wrong?
Remove web/app.php in Symfony2
Try this (i tested it with your examples and it is working fine):RewriteEngine on RewriteCond %{QUERY_STRING} ^(.*)&?query=[^&]+&?(.*)$ [NC] RewriteRule ^/?(.*)$ /$1?%1%2 [R=301,L,NE]Also, you should add a condition to apply this rule only on existing files (that's up to you).If you want it:RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{QUERY_STRING} ^(.*)&?query=[^&]+&?(.*)$ [NC] RewriteRule ^/?(.*)$ /$1?%1%2 [R=301,L,NE]
For reasons that aren't worth going into here, Google have been indexing one of my sites with an unnecessary query string in the URL. I'd like to modify my htaccess file to 301 redirect all those requests to the URL without the unneeded part of the query string, but retain any other parts of the query string which may (or may not) be part of the address to make sure other functionality is retained.For example, the following URLshttp://example.com/product.php?query=12345 http://example.com/index.php?section=ABC123&query=56789 http://example.com/search.php?query=987654&term=keywordWould becomehttp://example.com/product.php http://example.com/index.php?section=ABC123 http://example.com/search.php?term=keywordEffectively stripping 'query=XXXXX' plus the ? or &, but making sure other queries are retained and in correct syntax after the removal (i.e., just removing ?query=98765 from the third example wouldn't work, as it would leave the link as search.php&term=keyword rather than search.php?term=keyword).Was looking through some other Stack answers and found this:RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{QUERY_STRING} (.*)?&?query=[^&]+&?(.*)? [NC] RewriteCond %{REQUEST_URI} /(.*) RewriteRule .* %3?%1%2? [R=301,L]But that doesn't seem to work, and my knowledge of htaccess & regex isn't good enough to figure out why.Thanks in advance for any pointers.
Using htaccess to remove single query parameter