Response
stringlengths 8
2k
| Instruction
stringlengths 18
2k
| Prompt
stringlengths 14
160
|
---|---|---|
Finally I found the solution, easier than I though,In my main htaccess, I got :AuthType Basic
AuthName 'Acces Admin'
AuthUserFile "/home/www/fabrique/www/jeuxjuniorAugustins/.htpasswd"
Require valid-userAnd in each folders I want to allow access i added this small htaccess fileSatisfy anyI was just missing the correct syntax.
Now I must log on to access index.php and all folders but not for the ones where I put the small htaccess. | First time I post something here, usually I find what I need, I hope you could help me and maybe it'll help others too.I have a hand made mvc (only php/html/js/bootstrap) and I need to restrict few access but allow others, I tried few answers but nothing seems to work in my case.Here is my directory structure :Directory structureSo here is my problem, I want people to auth to allow access to index.php and all of the directories. This part is fine and very easy to setup. But I also need to allow them to access 3 folders without any auth ("/datas", "/datasProd" and also "/jeux").
I tried to add some htaccess in those folders where i wrote this in order to allow everyone :Order Allow,Deny
Allow from allAnd here is my root htaccess<Files index.php>
AuthUserFile "<path to my htpasswd>"
AuthName "Accès Restreint"
AuthType basic
require valid-user
</Files>
Order Allow,Deny
Deny from allWith this config I must auth to access index.php but I must auth too if I want to access the content of datas, datasProd, and jeux. I think the problem come from my root htaccess but I can't find out what's going wrong :/I tried to be as clear as possible but ask me if you need more information about my setup.Thanks for help ! and sorry for my english... | htaccess, auth to use index.php but allow some folder without any auth |
You can add exceptions inside a negative look-ahead:^(.*?)\/(?!(?:404|410)$)\d+$Seeregex demoThe look-ahead applies a restriction on the\d+(=1 or more digits) so that the digit sequence cannot be404or410.I am using a non-capturing group so as to keep the back-reference list clean. The$end of string anchor is very important in the look-ahead since it only limits the numbers excluded to exactly404and410(otherwise, it would also exclude41004). | Still new to Regex, I'd like to know how do you do that.The idea is to match any link which end with /23.../ (number) but not/410/and/404/The purpose is to put it in an .htacces so I can redirect old pages to 410.Every single old pages is in the shape ofhttp://www.blabla.com/something/2/http://www.blabla.com/something/3/etc ...So I've done this Regex which is working except it is including 404 and 410 too and that I can't allowed.^(.*?)\/\d+$https://regex101.com/r/tD2sX0/2I then tough of this one but this is not working properly since it does not capture my URL and I'm not sure why.^(.*?(404|410))\/\d+$https://regex101.com/r/tD2sX0/4A bit of help would be gladly accepted. | Regex match any link ending by digit except 404 and 410 |
I have experienced a very similar issue.Be ensured that module headers is enabled1 - To enable mod headers on Apache2 (httpd) you need to run this command:sudo a2enmod headersThen restart Apachesudo service apache2 restart2 - To allow Access-Control-Allow-Origin (CORS) authorization for specific origin domains for all files, add this in your .htaccess<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin https://example.org
Header set Access-Control-Allow-Origin https://example.com
Header set Access-Control-Allow-Origin https://example.eu
## SECURITY WARNING : never add following line when site is in production
## Header set Access-Control-Allow-Origin "*"
</IfModule>2 - To allow Access-Control-Allow-Origin (CORS) authorization for specific origin domains andfor fonts onlyin our example, use FilesMatch like in the following section in your .htaccess<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin https://example.org
Header set Access-Control-Allow-Origin https://example.com
Header set Access-Control-Allow-Origin https://example.eu
</IfModule>
</FilesMatch>After making changes in .htaccess file, no need to restart your apache webserver | We have been having the problem where we get errors of the format.Font from origin 'https://example.com' has been blocked from loading by
Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin'
header is present on the requested resource. Origin
'https://www.example.com' is therefore not allowed access.We also get a "Redirect at origin" error.We are using Drupal 7 and Cloudflare.we have attempted to edit .htaccess to includeHeader set Access-Control-Allow-Origin "https://example.com"
Header set Access-Control-Allow-Origin "https://www.example.com"Tried quite a lot;have purged cloudflarerestarted apachetried wildcard "*"Drupal CORS moduleSo far no joy.As this approach is not working, I am wondering if something is being missed or if there is an alternate approach, such as why we are getting origin 'https://example.com' being in the request via Drupal and not 'https://www.example.com'.Last note it that when I review some resources I see two distinct patterns.
If a resource has status of "301 Moved Permanently" in the request headers there isHost www.example.comRefererhttps://example.com/Where the status is "304 Not Modified"Host example.comRefererhttps://example.com/It's odd that there is any www at all; htaccess should be redirecting and it is absent from base_url. | CORS Access-Control-Allow-Origin Error on Drupal 7 with Cloudflare |
In .htaccessRewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]In config.php (application/config)$config['base_url'] = 'https://www.facebook.com/'; # set this to prevent HOST Injectio.
$config['index_page'] = ''; | I want to configure my htaccess file such when i type the folder name in small case or in upper case it will redirect to the same folder.Currently i have my file as :RewriteEngine on
#RewriteBase /ABC/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]The problem is when i try to access my controller giving the folder name in small case , it cannot find the controller.That is if i try something asabc/contrller_name/controller_functionit says path no found.
Note:Working on Windows System and using XAMPP | Codeigniter Htaccess configuration |
+50This is working fine on my server :RewriteCond %{THE_REQUEST} /produits\.html\?marque=([^&\s]+) [NC]
RewriteRule ^ /%1/bultex.html? [NE,NC,R,L]Remove or comment out the redirect line in your .htaccess and put this rule there. Don't remove the?from the end of the target url otherwise the query string "?marque=32" will be appended to it and the url will look like :/32/bultex.html?marque=32 | With magento 1.7 FR, I have some redirection rules in htaccess but not all are working and I can't find why :Options +FollowSymLinks
RewriteEngine on
# This is working
Redirect 301 /blog/conseils-literie/literie-et-matelas-pirelli.html http://example.com/produits/literie.html
Redirect permanent /catalogues/ http://example.com/
# This is not working !
Redirect 301 /produits.html?marque=32 http://example.com/32/bultex.html
# I replaced it with this but no way !
RewriteCond %{HTTP_HOST} ^example.com/produits.html?marque=32
RewriteRule ^(.*)$ http://example.com/32/bultex.html$1 [R=301,L]I'm sure there is no URL redirection set from the backend ! | magento : some htaccess redirection doesn't work |
You can use:RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Accept-Language} ^([a-z]{2}) [NC]
RewriteRule ^ - [E=LANG:%1]
RewriteCond %{QUERY_STRING} !(?:^|&)lang= [NC]
RewriteCond %{HTTP_HOST} ^(?:[^.]+\.)?(localhost)$
RewriteRule (.*) http://%{ENV:LANG}.%1/$1?lang=%{ENV:LANG} [QSA,L,R=302]Test.php:<?php
$lang = $_GET['lang'];
$content = array("en"=>"This is a test.","it"=>"Questo è un test.");
echo $content[$lang];
?> | ScenarioI've got the following code:test.php<?php
if(empty($_GET['lang'])){
$user_language = explode("-",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$language = $user_language[0];
header('Location: http://'.$language.'.localhost'.$_SERVER['REQUEST_URI']);
}
else{
$lang = $_GET['lang'];
$content = array("en"=>"This is a test.","it"=>"Questo è un test.");
echo $content[$lang];
}
?>.htaccessRewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^\.localhost$
RewriteRule (.*) - [QSA,E=LANG:%1]
RewriteRule (.*) $1?lang=%{ENV:LANG} [QSA]What my code should doIf $_GET['lang'] is not defined, get user's language from headers sent from his browser and redirect them to the subdomain that corresponds to their language: the subdomain should coincide to $_GET['lang'].What isn't workingBy visiting localhost/test.php, I get redirected to the right subdomain, but the redirect loops endlessly.
Plus, if I visit en.localhost/test.php and my language is Italian, I get redirected to it.localhost/test.php before the loop.My questionHow can I solve this problem? | GET parameter passed through an .htaccess subdomain not read by php |
You can have rules like this:RewriteRule ^articles/?$ articles/index.php [NC,L]
RewriteRule ^(en|el)/articles$ articles/index.php?lang=$1 [NC,L,QSA]
RewriteRule ^(en|el)/?$ index.php?lang=$1 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|el)/(.+)$ $2.php?lang=$1 [NC,L,QSA] | My page has 2 languages (in the near future will be 3). It has this structure on inner pages:domain.com/en/page (where page is page.php in main root)and the main page can be accessed throughdomain.comordomain.com/en/In my server I have all the files in the main root, and one folder named articles, where inside there are some other files.When I access the index of folder articles index likedomain.com/en/articlesit is ok.but when I access it likedomain.com/articlesit takes me to 404 page.How can I still open that folder without/en/or/el/in front of it?RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|el)/articles$ articles/index.php?lang=$1 [NC]
RewriteRule ^(en|el)(/)?$ index.php?lang=$1 [NC,L]
RewriteRule ^(en|el)/(.*)?$ $2.php?lang=$1 [NC,L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]Also, because I am new in htaccess please take a look at my overall code and tell me for any improvements. | What RewriteRule shall I add to my existing rules to fix this? |
Answering my own question.Actually there are two files in/etc/apache2/sites-available/defaultdefault-sslI put the rule to redirecthttptohttpsasRewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}indefaultfile andput rule to redirect to sub-domain'sfolderasRewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com
RewriteRule ^(.*)$ /folder/$1indefault-sslfile. | First case:I tried to redirect http to https and following rule works well.For example:http://subdomain.domain.comtohttps://subdomain.domain.com.RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}Second Case:
I tried to redirecthttp://subdomain.domain.comtohttp://subdomain.domain/folder. For this I used this rule:RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com
RewriteRule ^(.*)$ /folder/$1I want these redirection:http://subdomain.domain.comtohttps://subdomain.domain.com/folderandhttps://subdomain.domain.comtohttps://subdomain.domain.com/folderI tried merging the above rules but no luck.One more thing, I am not using.htaccess,instead I put these rules to/etc/apache2/sites-available/default. | Redirect http to https and then redirect it to subdomain's folder? |
I found the solutionhereBasically, installIIS URL Rewrite extension, and then create aweb.configfile on apigility's root with this content:<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<httpErrors existingResponse="PassThrough" />
<rewrite>
<rules>
<clear />
<!-- Rewrite rules to /public by @maartenballiauw *tnx* -->
<rule name="TransferToPublic-StaticContent" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="*assets*" />
<add input="{REQUEST_URI}" pattern="robots.txt" />
</conditions>
<action type="Rewrite" url="public/{R:0}" />
</rule>
<rule name="TransferToPublic" patternSyntax="Wildcard">
<match url="*" />
<action type="Rewrite" url="public/index.php" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="index.html" />
</files>
</defaultDocument>
</system.webServer>
</configuration> | I am in the process of deploying an API that I developed usingAPIGILITYto IIS. As IIS doesn't support .htaccess I am trying to create the web.config file from the contents of the .htaccess file. I used IISv7.5 and tried to install URL rewriter to convert the rules. But I get an error while I convert. Please find below the .htaccess file and the corresponding conversion I get from urlRewriter..htaccess fileRewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]the converted rules and errors I get.<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^.*$" />
<conditions logicalGrouping="MatchAny">
<!--The condition pattern is not supported: -s.-->
<!--The condition pattern is not supported: -l.-->
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<!--The rule cannot be converted into an equivalent IIS format because of unsupported flags: E-->
<!--This rule was not converted because it contains references that are not supported: 'ENV::BASE'-->
</rules>
</rewrite>Can I get some help around this? | htaccess rules (mod_rewrite) translation to web.config rules |
You need to setAllowOverridetoAllinhttpd.conf, or in your virtual hosts file (httpd-vhosts.conf) if you are using them.Otherwise, directives in your.htaccessfile will not be allowed.More information can be found here:http://httpd.apache.org/docs/2.2/mod/core.html#allowoverrideUpdateIf it is set toAll, then you should be able to do either of the following.Unset the handler and reset it:RemoveHandler .html .htm
AddType application/x-httpd-php .html .htmOr, useFilesMatch:<FilesMatch "\.(htm|html|php)$">
SetHandler application/x-httpd-php
</FilesMatch> | I want to add php code to my .html file. I have searched a lot and din't find why it is not workingSteps i have followed for this:1) Created a .htaccess file inside my htdocs2) And added the following thingsAddType text/html .shtml .shtm .htm .html
AddHandler application/x-httpd-php5.6 .html3) Restarted my Apache.Executed my page. My page contains<?php
echo "hello";
?>I din't see any errors and hello too. And i changed the htaccess content toAddType application/x-httpd-php .htm .htmlas mentionedhereIt is also not working. I don't know whether htaccess file must contain some other elements or not. Please let me know.Thanks | Adding php code to .html file |
This should be working<rule name="Remove question mark" stopProcessing="true">
<match url="^/?users/([^/]+)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/users/index.html?{R:1}" />
</rule> | This my first PHP application, I am using both.htmland.phppages in this website. If user browsesmysite.com/users/?abc123, it successfully loads details of user with id 'abc123' on plain html pagemysite.com/users/index.htmlvia Ajax. Now, I am tasked to remove?from the URL so that if user browsesmysite.com/users/abc123, thenmysite.com/users/index.html?abc123should serve the details successfully.I followedthis linkand added this rule to my web.config but that didn't seem to work and I received:Error: HTTP Error 404.0 - Not Found<rule name="Remove question mark" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^users/(.*)$" />
</conditions>
<action type="Redirect" url="users/?{R:0}" redirectType="Permanent" />
</rule>Please assist me with following concerns in mind:I can only use web.config for URL rewriting (to keep things simple)The page I want to rewrite URL for is .HTML not .PHP (if that matters)I am testing my PHP site locally in IIS 8 configured to serve PHP | Php: Rewrite URL using web.config |
Try this rule in virtual host config file:RewriteEngine on
RewriteRule ^/?macmillan\xE2\x80\x99s-st-luke-passion$ http://newdomain.com/tickets/events/macmillans-st-luke-passion [NC,R=301,L]Leading slash is required while matching in Apache or vhost config but not when used in htaccess. Make sure to test in a new browser to avoid old cache. | I'm trying to get the following URL:http://olddomain.com/macmillan’s-st-luke-passionWhich contains the RIGHT SINGLE QUOTATION MARK character (http://www.fileformat.info/info/unicode/char/2019/index.htm)To redirect to a new location. However, I cannot get Apache to do this.For reference my redirect code (in a VirtualHost) is as follows:RewriteEngine on
RewriteRule ^macmillan\xE2\x80\x99s-st-luke-passion$ http://newdomain.com/tickets/events/macmillans-st-luke-passion [R=301,L]The file has other redirects for exact matching URLs, and one catch all redirect at the bottom of the page. This one is intended to match any remaining URLs to/events/(old url). For example, it will sendolddomain.com/page-titletonewdomain.com/events/page-title.Redirect 301 / https://newdomain.com/events/What's happening at present is Apache is ignoring the specific rule which contains the\xencoded string for the right quote character’.And falls through to the fallback redirect that sends the URL to the wrong place.Can anyone help with how to match a URL with a right quote character’in an ApacheRewriteRule(orRedirectMatch)? | How to match right single quotation mark character in an Apache RewriteRule |
The following code should helpadd_action( 'init', 'so_27487849' );
function so_27487849() {
add_rewrite_rule(
'^brand/([^/]*)/mtype/([^/]*)/?',
'index.php?name=$matches[1]&mtype=$matches[2]',
'top');
}Flush your permalinks and it should work. | I want to change the permalink structure for specific custom post type.i.ehttp://test.com/brand/calvin-klien?mtype=tab2
^this is dynamicTohttp://test.com/brand/calvin-klien/mtype/tab2
^this is dynamicHere is a piece of code I tried.Registering add_rewrite_tagfunction custom_rewrite_tag() {
add_rewrite_tag('%mtype%', '([a-z0-9\-]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);
add_action('init', 'wpse50530_journal_archive_rewrite', 10, 0);Code1function wpse50530_journal_archive_rewrite(){
add_rewrite_rule('brand/([a-z0-9\-]+)/([a-z0-9\-]+)/$','index.php?name=$matches[1]/?mtype=$matches[2]','top');
}Code2add_action('generate_rewrite_rules', 'work_list');
function work_list($wp_rewrite) {
$newrules = array();
$newrules['brand/([a-z0-9\-]+)/([a-z0-9\-]+)/$'] = 'index.php?name=$matches[1]&mtype=$matches[2]';
$wp_rewrite->rules = $newrules + $wp_rewrite->rules;I have tried both abovecodes,flushed permalinksbut still a404. I dont know why it is creating$matchesin htaccess as htacces doesnt know WHAT IS$matchesAlso I have triedmonkeyman-rewrite-analyzer pluginwhich is showing the correct matched result for my permalink but still word press showing404. See attached screenshots for Code1 & Code2 | Wordpress add_rewrite_rule gives 404 |
You must rearrange your directives:# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks -Multiviews
Options +SymLinksIfOwnerMatch -Multiviews
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+single\.php\?name=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [L,R=301]
RewriteRule ^page/(.*)$ single.php?name=$1 [L,NC,QSA]
RewriteCond %{THE_REQUEST} \s/+(Web/2015/wessexcars)/internalpage\.php?seo=\?name=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [L,R=301]
RewriteRule ^(Web/2015/wessexcars)/(.+?)/?$ $1/internalpage.php?seo=$1 [L,NC,QSA] | i am trying to convert the actual URL to user friendly there is dynamic menu, when user click on page the orignal url becomeshttp://example.com/single.php?name=mypagenamei want to change it tohttp://example.com/page/mypagenamehere is my htaccess file i tried from different angles Please can any one help to correct it..# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks -Multiviews
Options +SymLinksIfOwnerMatch -Multiviews
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /single\.php(\?|\ )
RewriteCond %{QUERY_STRING} name=(.+)
RewriteRule page/(.*) single.php?name=$1
RewriteRule ^ /page/%1? [L,R=301] | how to write htaccess file, to change URL |
Why not just match for everything? I'm not sure the-character range works the way you're using it:RewriteRule ^test/([0-9]+)/(.+?)/?$ test.php?id=$1&title=$2 [NC,L] | I write a regular expression so that it works when using the term Persian.
I'm using the following code but the following code does not work.RewriteRule ^test/([0-9]+)/([\u0600-\u06FF]+)/?$ test.php?id=$1&title=$2 [NC,L] | rewrite rule in .htaccess - regex for persian |
TL;DR- Use some javascript to manipulate the url onclick, reassemble the URL the way you wish, reload new URL.I did a bilingual shop once and inserted an 'es' or an 'en' into the path to signify Spanish or English, essentially as a URL parameter. Your goal is a bit more complicated (I'll assume it has to be) but this might get you started. You can see theshop here(not my design -- don't blame me. Much of it is offline at the owner's request (some legal stuff) but you should be able to navigate some pages and see the language toggle in effect.)Clicking a language toggle triggers some simple Javascript as follows:function switchLanguage(lang) {
u = location.href.split('/');
u[3] = lang;
location.href = u.join('/');
}And then anonclickis added to the language toggle links to directonclick="switchLanguage('en')"oronclick="switchLanguage('es')", or whatever your URL injection is to be. Again, this is specific to my example where the URL parameter was going to follow the third forward slash (u[3] = lang), but this should get you started on dicing up your URL for manipulation and reassembly.There are some excellent exampleshere.Of course, the localized versions of my site needed to reside under those url paths (in my case, I changed some PHP global variables to account for the different language codes in the URL, so the under-the-hood stuff is really minimal) but this is one method to get you started on how to split/alter/replace your URL onclick. | I have tried to look for answers here and on google, but maybe I'm not using the correct search terms... I just can't find it.
Hope anyone can help me with this.On abi-lingualshop I want a person to be redirected to the same product on a differentdomain/url, when clicking theenglish flagbutton.www.mydomain**.nl/a1**/product1.htmlis the starting point. Clicking on the english flag should grab the domain and category and change this and go to the newly created url:www.mydomain**.com/a2**/product1.htmlthenwww.mydomain**.nl/b1**/product1.html,becomes after clicking the 'english flag' button:www.mydomain**.com/b2**/product1.htmletc.There are about 30 different pages to be redicted like this, all with the same 'english flag' button.IF part of url is '.nl/schoenen/' THEN change and go to '.com/shoes/'IF part of url is '.nl/jassen/' THEN change and go to '.com/jackets/' | Replace part of URL onclick and redicrect |
Regarding your first question:If you don't want search engines to gain access to the subdomain (sub.example.com/robots.txt), using a robots.txt file ON the subdomain is the way to go. Don't put it on your regular domain (example.com/robots.txt) - seeRobots.txt reference guide.Additionally, I would verify both domains inGoogle Search Console. There you can monitor and control the indexation of the subdomain and main domain.Regarding your second question:I've found a SO thread here which explains what you want to know:Block all bots/crawlers/spiders for a special directory with htaccess. | Hello i have a multistore multidomain prestashop installation with main domain example.com and i want to block all bots from crawling a subdomain site subdomain.example.com made for resellers where they can buy at lower prices because the content is duplicate to the original site, and i am not exacly sure how to do it. Usualy if i want to block the bots for a site i would useUser-agent: *
Disallow: /But how do i use it without hurting the whole store ? and is it possible to block the bots from the htacces too ? | Block Bots from crawling one of my sites on a multistore multidomain prestashop |
You can set thefull pathlinking to your root folder, to make your rule directory-recursive. You can see the path on your cPanel, or using php functiongetcwd()inrun_me_first.php.In my case the path would be like this:php_value auto_append_file "/home/userID/public_html/run_me_first.php"Note: If you want to prepend file(in this case your appending the file to the end of every file), useauto_prepend_fileinstead. | In my .htaccess filephp_value auto_append_file "run_me_first.php"Because I want to run it first before any other file. Now it works ifrun_me_first.phpandfoo.phpare in the same directory but once I do something like going in a directory, it gives me this error(include_path='.:/usr/share/php:/usr/share/pear')root
|_ .htaccess
|_ run_me_first.php
|_ foo.php
|_ folder1
|_ bar.php // If I try to access this, give me the error above.Any idea? | include a directory path in .htaccess |
You need a new rule like this:RewriteCond %{THE_REQUEST} \s/+post\.php\?author=([^&]*)&title=([^\s&]+) [NC]
RewriteRule ^ post/%1/%2? [R=302,L]
RewriteRule ^post/([0-9]+)/([\w-_:]+)/?$ post.php?author=$1&title=$2 [L,QSA,NC] | I have this linkwww.example.com/1/titlewhich goes towww.example.com/post.php?author=1&title=titlebecause of this ruleRewriteRule ^post/([0-9]+)/([\w-_:]+)/?$ post.php?author=$1&title=$2 [L,QSA,NC]Fine, but now how do make it such that if somebody types in www.example.com/post.php?author=1&title=title to redirect to www.example.com/1/titleI have spent literally hours online researching this but the information is vague (at least for me) and not working.2 things stump me so far:Writing the pretty url into dynamic and then dynamic into pretty -
Doesn't that create a loop?I also wanted to go the route of a 301 redirect but I could not find
any workable code that take variables from the first link to put into
the redirect. In my head a 301 would be the right choice, but I see a
lot of people (examples) doing it through RewriteRule.I understand that (groups) can later be accessed by using $1 and $2... but when trying the reverse I cannot make it work. Eg:RewriteRule ^post.php?author=([0-9]+)&title=([\w-_:]+)$ post/$1/$2But like I said nothing works. I've been beating my head on sites likehttp://httpd.apache.org/docs/2.2/mod/mod_rewrite.htmlbut I cannot fully understand (or apply) what I'm reading there. Can you please let me know what I'm doing wrong or how I should approach this problem?Many thanks for any help you can give me | Apache Mod_Rewrite Htaccess for Dynamic URL |
maybe it's too late for the answer but I hope it can be useful.have you tried checking apache's httpd.conf file? Mine contains these lines:LogLevel error
ErrorLog /app/logs/apache/error/my_log_file.log
CustomLog /app/logs/apache/access/my_log_file.log combinedThese lines keep overriding .htaccess configuration, maybe this is also your case...Hoping to be helpful | I need to logPHP errorto.logfile using.htaccesswithlog_errors:# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
# enable PHP error logging
php_flag log_errors on
php_value error_log C:\xampp\htdocs\cms\cache\logs\PHP_errors.log
# prevent access to PHP error log
<Files PHP_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>Now, This not work and.logfile is empty.NOTE:I change.logfile to777permission.I know,xampplogPHP errorto this file :C:\xampp\php\logs\php_error_log.log | Log PHP error Into file in xampp localhost using .htaccess |
Try thisRewriteEngine on
RewriteRule ^(.*)$ http://192.168.0.1:1234/$1 [R=301,L] | I am trying to redirect url as abc.xyz.org to 192.168.xx.yy:abcd using htaccess.
tried using following in htaccess.RewriteRule ^(.*)$ 192.168.xx.yy:abcd [P,R=301,L]but this rule isn't taking the port number.What should I do?
i triedRewriteRule ^(.*)$ 192.168.xx.yy:abcd[b] [P,R=301,L] | how to redirect certain url to port using .htaccess |
This line:AllowOverride AuthConfigIs probably what's causing you the error. TheAllowOverridedirective tells apachewhat is allowed to be used in things like htaccess files. So obviously, it's not something you can setin your htaccess file.AllowOverrideneeds to be in the server or vhost config, and theAuthConfigpart of it tells apache that you can have auth directives (like AuthType, AuthName, etc) in an htaccess file. | sorry to ask this again, I know that it's been asked before but I've literally read every discussion for trouble shooting and I'm still having problemsheres my code:AllowOverride AuthConfig
AuthUserFile path/index/.htpasswd
AuthType Basic
AuthName "restricted area"
AuthGroupFile /dev/null
require valid-userwhenever I delete the .htaccess from the server the pages run normally but when I re-add the .htaccess I get the internal server error. It's really weird because occasionally an enter your password window comes up even but when I enter the password the window reappears, as if the password was entered incorrectly, and when I reload the page I get the 500 server error. Thanks in advance for the much needed help!!! | 500 internal server error with .htpasswd/.htaccess |
You should place your.htaccessfile into theinclude/directory, if it's not the case.
I think you used theFilesMatchsyntax for aFilestag.<FilesMatch "^.*\.php$>
order deny,allow # Deny here, allow later.
deny from all
</Files>
<FilesMatch "^(index|key)\.php$">
allow from all # Allow here.
</Files>Then, in your root (public_html/), you can use :ErrorDocument 403 /error.html
# Try ../error.html if you put this line in include/.htaccessMake sure the path toerror.htmlis valid. If you see something like "an error was encountered looking for the error document", then it's wrong (try absolute path from the Linux root ?) | How do I setup a .htaccess that denys any.phpfile access in theinclude/folder, and redirect user toerrorpage in thepublic_html/(root) directory when 403, 404 and 500 occurs, but except for 2 files that are calledindex.phpandkey.php?Currently this is what I have:<Files "^*\.php$">
order allow,deny
deny from all
</Files>
ErrorDocument 403 /error.html
ErrorDocument 404 /error.html
ErrorDocument 500 /error.html
<FilesMatch "^(index|key)\.php$">
Allow from all
</FilesMatch>but this does not work properly, only<FilesMatch "^(index|key)\.php$">works fine.Thanks! | .htaccess deny from all, redirect to 404 page and except for 2 files |
Enable mod_rewrite and .htaccess throughhttpd.confand then put this code in your.htaccessunderDOCUMENT_ROOTdirectory:Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \?.+?\.\.
RewriteRule ^ /? [R=301,L,NE] | Google webmaster showing some duplicate url,
They arewww.abc.com/index.php?option=com_toys&view=detail&n_id=148&ite..
www.abc.com/index.php?option=com_toys&view=detail&n_id=156&item..
www.abc.com/index.php?option=com_games&view=detail&vid=170&itemid..
www.abc.com/index.php?option=com_play&view=detail&vid=175&it..To remove them - i feel the best way is to redirect to home page for any url containing..at end of urltried putting this condition, but it does not work tooRewriteRule ^(.*)\.htm$ http://www.abc.com/$1 [R=301,L]
RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R=301]
RewriteRule ^(..*)\.htm$ http://www.abc.com/$1 [R=301,L]Correct url structure arewww.abc.com/index.php?option=com_toys&view=detail&n_id=148&Itemid=2
www.abc.com/index.php?option=com_toys&view=detail&n_id=156&Itemid=2
www.abc.com/index.php?option=com_games&view=detail&vid=170&Itemid=3
www.abc.com/index.php?option=com_play&view=detail&vid=175&Itemid=4any suggestions pls ... many thnxEdit on 13th SepHello Anubhav,If we have redirect these URL to 404 page then is below command in htaccess correctRewriteCond %{THE_REQUEST} \?.+?\.\.
RewriteRule ^index\.php$ - [NC,L,R=404] | Redirect url to home page with trailing dots |
Almost any restriction you put on it will essentially come down to "Put something in the request that only the application will send".The basic approach would be "Keep the URL secret". If only the application knows about it, then only the application can make a request to it. Anything else (passwords, API keys, custom HTTP headers, user-agent sniffing, etc) is just complexity around the same concept.Making the request over HTTPS instead of HTTP will protect the secret from exposure to sniffing.Nothing can save you from decompilation though. | This question already has answers here:Prevent direct access to a php include file(33 answers)Closed11 years ago.I have a PHP file that queries my database and then returns information in XML format back to my application. Right now, if I just go to the URL in the browser and put in the proper parameters in the URL, the information is shown right to me. Is there a way that I can make the PHP page ONLY accessible through the application(iOS and Android)? I have searched, and the only thing that I can find is making the page only accessible through includes, but I don't see how this would restrict the access if the person figured out the php page that included the file. Any suggestions are appreciated!Thanks | Only allow access to PHP file through application [duplicate] |
Have a look at following article. Hope it describes clear/simple and with example what you need.SEO Friendly URLs with PHP | Clicking on user John Smith in positionuser_id1 It should go to the url www.example.com/John-Smith as opposed to profile.php?uid=1When you click on user John Smith inuser_id2 It should go to the url www.example.com/John-Smith-2
profile.php?uid=2When you click on user Kia Dull inuser_id3 It should go to the url www.example.com/Kia-Dull
profile.php?uid=3Table Users
User_id First_name last_name
1 John Smith
2 John Smith
3 Kia DullHow do I format my .Htaccess file and php/sql for this.When a user profile is clicked I just simply lead it here.<a href="<?php echo $row[first_name] ?>-<?php echo $row[last_name] ?>"which doesn't do anything.and here's my .htaccessRewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ profile.php?uid=$1 [L] | Creating dynamic auto-incrementing seo friendly url's from php and sql |
Apache docsare pretty clear:The configuration directives found in a .htaccess file are applied to the directory in which the .htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree. And those, in turn, may have overridden directives found yet higher up, or in the main server configuration file itself.This is a feature of Apache, not of cPanel. It does not matter if you're running with cPanel or not — Apache is still going to traverse parent directories and apply their.htaccessdirectives. | When you have cPanel hosting and you use addon domains, the domains are "housed" in a folder within thepublic_htmlfolder (by default), for example:A) public_html/.htaccess
B) public_html/addondomain_1/.htaccess
C) public_html/addondomain_2/.htaccessIt's my understanding that anything I put in the htaccess file A) applies to everything within it, which should include B) and C).So, as an example, adding a blocked IP address to A) would also be blocked on B) and C).But I query this purely because B) and C) are different domains when viewed in the browser. I've tried testing it but without much luck and going through pages of documentation hasn't helped me come to a conclusion.If I block someones IP in A) will it block them from websites B) and C)? | How does htaccess work when using cPanel and addon domains |
As long as you don't have any legitimate requests for anything containing "phpmyadmin", then you can simply do add this rule near the top of the htaccess file in your document root:RewriteRule phpbbadmin /bottrap/index.php [L]Include theRflag if you actually want to redirect the request:[L,R].I figured just for good measure I'd add a deny to all in the robots.txt file and say thanks for the visit by contributing the ip address to the honeypot project.I doubt these bots honor the robots.txt file. If anything these are compromised websites or otherwise users unwittingly hosting malicious code either on their websites or home PCs. You can include aDENY From <ipaddress>in the htaccess file if the requests get annoying, but adding them in the robots.txt probably isn't going to do much.Adding NC makes it pick up case variations.RewriteRule phpmyadmin /phpmyadmin/index.php [L,NC] | I'm hoping someone can help as I'm a bit of a noob when it comes to apache mod rewrite, and getting this one wrong can screw things up pretty bad.While going though my security logs I noticed that almost 50% of the attacker bots had
the string phpmyadmin (different case, sometimes with version numbers in it). i.e.hhhh://www.example.com/phpmyadmin/hhhh://www.example.com/something/phpMyAdmin/hhhh://www.example.com/something/morestuff/phpMyAdmin/hhhh://www.example.com/phpMyAdmin-2.11.3/scripts/setup.phpetc. etc. etc.I'm wondering is there a way I can use mod rewrite to trap all of these and send them tohhhh://www.example.com/bottrap/index.phpor something similar. (hhhh -> http - spam protection wouldn't allow http)I figured just for good measure I'd add a deny to all in the robots.txt file and say thanks for the visit by contributing the ip address to the honeypot project.I can handle the php stuff, but even after reading mod rewrite documentation, I'm still pretty lost. Any help would be much appreciated. | Trapping Bad Behavior with rewrite -phpmyadmin anywhere in URL |
i figured it out, this code works for me.Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
rewritecond %{HTTP_HOST} ^inaflashgraphics.com$
rewriterule ^ "http\:\/\/www\.inaflashgraphics\.com\/" [R=301,L]
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_URI}.php [L]
# Redirect to HTML if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA] | I have a URL rewrite that strips away the file extension. It's working with.htmlpages but it gives me a "404 Page Not Found" error with.phpfiles.Here is my full.htaccessfile# The following will allow you to use URLs such as the following:
#
# example.com/anything
# example.com/anything/
#
# Which will actually serve files such as the following:
#
# example.com/anything.html
# example.com/anything.php
#
# But *only if they exist*, otherwise it will report the usual 404 error.
Options +FollowSymLinks
RewriteEngine On
rewritecond %{HTTP_HOST} ^inaflashgraphics.com$
rewriterule ^ "http\:\/\/www\.inaflashgraphics\.com\/" [R=301,L] #4e2f2fa615667
# Remove trailing slashes.
# e.g. example.com/foo/ will redirect to example.com/foo
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=permanent,QSA]
# Redirect to HTML if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
# Redirect to PHP if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]What am i doing wrong? | URL rewrite working for .html but not .php |
If you are like me you are trying to avoid adding leading slashes to your substitution URL (the new destination) so that your same.htaccessfile can work with both your test and production servers. I had the same problem you were having and all that was needed was to set:RewriteBase /This tells mod_rewrite to base the substitution URLs off of the web root rather than the file root. Another tip, if you need to redirect to the top level of the destination, use./instead of just/. My test server has a port (8080) and is not at the root (so it has a non-emptyRewriteBaseof/site1/), and most of the rewrite rule examples on the web do not consider this case. If you never have your substitutions start with a leading slash, you can use the same.htaccessfile on your test server and live server, and all you might need to change is the value ofRewriteBase, rather than updating every single rule. | I've created a bunch of RewriteRules for my website and have had no problem with them on my local setup. Here's a snippet from my .htaccess:Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^news/?$ news.php [L]Locally, when I visit 127.0.0.1/news, it redirects properly to news.php and masks the URL. I just updated the .htaccess file on the remote server and receive this error, when trying to visit the above example:The requested URL /mnt/target02/123456/123456/www.mywebsite.com/web/content/news.php was not found on this server.I've tried changing the rule to this:RewriteRule ^news/?$ http://www.mywebsite.com/news.php [L]and the page loads properly. However, the address bar shows news.php, rather than news. Is there something I am missing, or am I stuck with the ugly (and less secure) address?
Thanks! | RewriteRule is redirecting to an absolute path, rather than the proper URL |
Subdomains are a bit different than directories. You need to have awildcard DNS recordto catch all subdomains:*.example.com. 3600 IN A host1.example.com.Best thing to do would be to contact your hosting provider. Some of them have settings to achieve that. | I'm trying to redirect all subdomains at(http://*.domain.com)to spesific html file(http://domain.com/index.html). But I also want to visible subdomain name won't change.I've tried this one with .htaccess:Options -MultiViews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#RewriteCond %{REQUEST_URI} !^/parent/
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$
RewriteRule (.*) /index.html [L]But it doesn't work at all.Can anyone help me? | Redirecting all subdomains to one page |
Humm I'm not a pro with htaccess, but if the user types a wrong sub domain he'll get a 404 error. So redirect him to your domain if he gets it.ErrorDocument 404 domain.com | I need to Display an custom url source,when users mistype an subdomain.For example , If user typeshames.domain.cominstead ofgames.domain.com, Thehames.domain.comshould display html source of index ofdomain.com.P.s : i dont want iframe or redirection,It needs to display index of main domain.i tried below codeRewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteRule ^%1/(.*)$ /$1 [L,NC] | htaccess : Display homepage on wrongly typed subdomain |
Try this instead of what you have:RewriteEngine On
# for main domain
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.eu/$1 [L,R=301]
# for all subdomains
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://%1.domain.eu/$1 [L,R=301] | is it possible to redirect entire domain to another?I want it to redirect this way:domain.com/something --> www.domain.eu/something
sub.domain.com/folder/file.type --> sub.domain.eu/folder/file.type
super.mega.sub.domain.com --> super.mega.sub.domain.eu(For any subdomain and anything after /.)I have access only to com domain.So far I have invented this code for .htaccess file:RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule (.*)$ http://www.domain.eu/$1 [R=permanent,L]But it work like:sub.domain.com/something --> www.domain.eu/sub/somethingSo it is wrong.
Any help please?
Thanks very much. | Redirect whole domain |
Add this to your htaccess file in your document root:RewriteCond %{QUERY_STRING} ^f=12&t=345$
RewriteRule ^forum/viewtopic.php$ /landing-page.html [R=301]Essentially you want to match the query string in thisRewriteCondand the URI in theRewriteRule. | I've seen several questions regarding similar requests, however, I'm not trying to redirect to a custom crafted URL. I just want to take common URLs that have been linked to and redirect them to a landing page.For example, I want to catch a specific URL like the following, but only this URL:http://example.com/forum/viewtopic.php?f=12&t=345...and redirect it to:http://example.com/landing-page.htmlI have a few links which no longer exist, so I'll be adding 4 or 5 redirects to more useful pages since they're currently hitting 404's.Thanks in advance! | .htaccess RewriteRule to redirect url's containing specific parameters |
The[L]flag tells Apache to stop the redirection after the rule was matched. So assuming your ROOT folder comes first, it will run and stop at the redirection, which would render the second redirect useless.To fix the problem have this:RewriteEngine on
RewriteRule ^$ public/
RewriteRule (.*) public/$1 | I'm building a php framework that redirects all traffic to ROOT/public/index.php and then puts the url in a get request. My problem is that my RewriteConds aren't working and are accepting files and foldernames.in root directory<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
<files .htaccess>
order allow,deny
deny from all
</files>in public directory<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule> | Mod_rewrite - rewrite conditions aren't working |
Try to add a RewriteBase with this code:RewriteBase /Depending on the server configuration it is possible that%{REQUEST_FILENAME}contains a slash at the begining which would produce an absolute and not a relative path. | I've got a problem with rewriting urls.
The following is happening:http://www.example.com/scores
http://www.example.com/registreren
http://www.example.com/loginthese urls will be redirected toindex.php?route=scoresetcThis is all working very well. But now I've got template files in a subdirectory likeimagesandstylesheet. These files are intemplate/css/style.cssimages/images.pngetcnow all those files are also being redirected toindex.php?route.
I'm aware of the leading slash and all links to the files are absolute paths.The following code is being used in the.htaccessfile:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ index.php?route=$1 [L,QSA] | Static resources being incorrectly rewritten to front-controller index.php |
Less can do that:http://lesscss.org/#-importingMaybe sass also, but I'm not sure | We are building a large site which requires very modular CSS. The problem we have is that we like using the@importstatement as it's very clean, but the major downside is the performance (all CSS files referenced are loaded synchronously i.e. not in parallel).Does anyone know of a way to use PHP (or even .htaccess) to find any CSS files referenced via@importand then generate a single CSS file?I've looked at loads of examples (some of which are seen here):http://robertnyman.com/2010/01/19/tools-for-concatenating-and-minifying-css-and-javascript-files-in-different-development-environments/but none of them work [email protected]. | How can I concatenate CSS files using @import? |
use this,RewriteRule ^aaddress-state-([^-]+)-office_id-([^-]+)-office_name-([^-]+)-state_name-([^\.]+)\.php$ aaddress.php?state=$1&office_id=$2&office_name=$3&state_name=$4^and$will match the whole url and[^-]+will match anything unless-is encountered. And[^\.]+will match anything unless.is encountered.This will matchaaddress-state-nm-office_id-852-office_name-CLOVIS-state_name-New Mexico.phpButnotaaddress-state-nm-office_id-852-office_name-CLOVIS-state_New Mexico.php.Notethe missingname-part instate_New Mexicoin the later URL. | Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed12 years ago.Improve this questionI have the below urlhttp://www.***.org/aaddress.php?state=nm&office_id=852&office_name=CLOVIS&state_name=New%20MexicoI want to change it the below urlhttp://www.*****.org/aaddress-state-nm-office_id-852-office_name-CLOVIS-state_New%20Mexico.phpI have used below htaccess codeOptions +FollowSymLinks
RewriteEngine on
RewriteRule aaddress-state-(.*)-office_id-(.*)-office_name-(.*)-state_name-(.*)\.php aaddress.php?state=$1&office_id=$2&office_name=$3&state_name=$4It's not working, when i click write the address didn't convert to the .php pageMy links inside the pages as the 1st link and want to change it as the .php link | htaccess url rewrite to .php [closed] |
You could also try adding the following to your .htaccess file instead.<IfModule mod_header.c>
<FilesMatch "\.ico$">
# cache .ico files for 1 year(31536000 sec)
Header set Cache-control max-age=31536000
</FilesMatch>
</IfModule>EDIT:Note, that you haveAddType image/ico.icobur you are usingExpiresByType image/x-icon"access plus 1 years"which could also be the issue. To resolve, you could change toAddType image/x-icon.ico | I asked my developer to to set an expire date for the favicon by adding to the .htaccess file the following line:<IfModule mod_expires.c>
ExpiresByType image/ico "access plus 1 years"But it didn't have an expire date, couldn't figure it out till I loaded the icon in Firefox and noticed this part of the response headersContent-Type: text/plain; charset=WINDOWS-1251I was then advised to add the following: (to get Apache to set the correct mime type for the favicon)<IfModule mod_mime.c>
AddType image/ico .ico
</IfModule>But it didn't do the trick, not sure why, can there be any conflict that overrides the mod_mime.c? or any other reason?Please adviseThanksAdded: I currently have this to set expire date:<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 years"
ExpiresByType image/jpeg "access plus 1 years"
ExpiresByType image/png "access plus 1 years"
ExpiresByType image/x-icon "access plus 1 years"
ExpiresByType text/css "access plus 1 years"
ExpiresByType text/javascript "access plus 1 years"
ExpiresByType application/x-javascript "access plus 1 years"
ExpiresByType application/x-shockwave-flash "access plus 1 years"
</IfModule> | Favicon Content-Type: text/plain - "AddType image/ico .ico" doesn't work |
Here's my solution:RewriteEngine On
RewriteCond %{REQUEST_URI} ^([^/\.]+)/?
RewriteCond %{DOCUMENT_ROOT}/%1/.content -f
RewriteRule ^([^/\.]+)/? struct.php?page=$1 [PT,QSA,L] | here's how I do :the user types a URLthe mod_rewrite handles URLs of the form :^([^/\.]+)/?$(the first
segment in the path)and redirect them to the index page :struct.php?page=$1in the index page (struct.php) I request the content of the page
($_GET['page']) if it exists :$content = @file_get_contents("pages/$_GET[page]/.content")if the content doesn't exist, I just request the content of the page'not_found/.content'This is working but I'd like to keep things simple in the script and use the power of mod_rewrite to request only the pages that exist.here's how I'd like to do :the user types a URLthe mod_rewrite handles URLs of the form :^([^/\.]+)/?$(the first
segment in the path)and redirect them to the index pageonly if the.contentfile has been found:struct.php?page=$1here's my try:<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond pages/$1/.content -f
RewriteRule ^([^/\.]+)/?$ struct.php?page=$1 [L]
</IfModule>note: I'm using an.htaccessfile | substituting an URL only if a file was found using mod_rewrite |
I solved it by replacing " " with \s in the regex. I had completely forgotten that a regular space basically jumps to another argument. | I'm using this line to match only certain browsers:RewriteCond %{HTTP_USER_AGENT} !((Chrome|Firefox|Safari|Opera)\/\d+(\.\d+)*|(MSIE|Opera) \d+(\.\d+)*|Maxthon)But for some reason it gives me error 500. I tried the regex with PHP's preg_match, and it works just as I intended... Does anyone know what the problem could be?Note: I'm negating the condition because I want to ban other browsers. | Apache gives Error 500 with RewriteCond Regex |
RewriteRule ^addonedomain/(.*)$ http://addondomain.maindomain.com/$1this code will redirect user frommaindomain.com/addonedomaindirectory toaddonedomain.maindomain.com!
it's better to put this code in.htaccessfile in root of add-on domain! | I am planning to create some addon domains through cPanel, I'm aware that their content can be accessed by visitingaddondomain.maindomain.comandmaindomain.com/addondomain- this could lead to duplicate content with search engines, amongst other things, so I would like to prevent this if possible.After some research it seems the best (probably only) option would be to use .htaccess and rewrites so that the addon domain can only be accessed at www.addondomain.com - what is the best way to go about doing this and can I have the .htaccess file within themaindomain.comdirectory or will I need it for each addon domain I create?Any help would be much appreciated, thank you :) | htaccess - rewrites/redirects for addon domains? |
Because you mentioned mod_rewrite, I was able to use the following mod_rewrite .htaccess code to produce the effect you want:RewriteEngine On
RewriteRule ^(.+)/?$ index2.php [CO=testcookie:%{REQUEST_URI}:localhost,R,L]I get a cookie set with the current URI and a redirect to index2.php as expected.COsets a cookie (name:value:domain),Ris redirect,Lmeans "last rule". Of course, you'll have to change cookie domain, path and lifetime information as appropriate. More informationhere.Is this what you were trying to accomplish? | <?php
setcookie('a', $_SERVER['REQUEST_URI']);
header(location: "index2.php");
?>im new to .htaccess and wonder how to convert this php script to .htaccess codehere are lines what I tried with .htaccess, but din't work:Header set Set-Cookie a=REQUEST_URI
Header set Set-Cookie "a=REQUEST_URI; path=/;"
Header set Set-Cookie "language=%{REQUEST_URI}e; path=/;"is there any way of doing this in mod_rewrite?:) | PHP to htaccess? |
Themod_alias Redirectdirective doesn't look at the parameter string, so your Redirect statement will never match. Instead, you'll need to use mod_rewrite. You can do something like the following:Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^suma\.ir$ [NC]
RewriteRule ^(.*)$ http://www.suma.ir/$1 [R=301,L]
RewriteCond %{QUERY_STRING} (^|&)id_product=12(&|$)
RewriteRule ^product\.php$ /$0?id_product=508 [R=301,L] | I want to redirect "http://www.suma.ir/product.php?id_product=12" to "http://www.suma.ir/product.php?id_product=508" but I'm having trouble. The URL path should stay the same, all I want to do is change the ID in the query string. What do I need to do to make this work?Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^suma\.ir$ [NC]
RewriteRule ^(.*)$ http://www.suma.ir/$1 [R=301,L]
# This is the part that isn't working
Redirect 301 /product.php?id_product=12 http://www.suma.ir/product.php?id_product=508 | How can I change the value of a query string parameter with a redirect? |
If you do have access to your apache VirtualHosts configuration then you need:<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>This will succesfully redirecthttp://example.com/tohttp://www.example.com/andhttp://example.com/dir/state/AK/35827/tohttp://www.example.com/dir/state/AK/35827/ | Assume/is the document root of my domainexample.com./.htaccessRewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]/dir/.htaccess<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dir/index.php [L]
</IfModule>I know how to redirectexample.com/dirtowww.example.com/dir, because/.htaccessdoes the very job.However, the trick here is that I have to keep/dir/.htaccessto serve up virtual directories (such as/dir/state/AK/35827/which aren't actual directories) if you know what I mean.Problem is, if I keep/dir/.htaccess, a request of:http://example.com/dir/state/AK/35827/DOES NOT redirect to:http://www.example.com/dir/state/AK/35827/as would:http://example.com/redirect to:http://www.example.com/Not sure if I made it clear.Basically, how to makehttp://example.com/dir/state/AK/35827/correctly redirect tohttp://www.example.com/dir/state/AK/35827/AND I can serve virtual URLs? | Use mod_rewrite to redirect from example.com/dir to www.example.com/dir |
This was driving meMAD!but I found the answer, for those who are getting confused like I was.Look at line 4:Options +FollowSymlinks
RewriteEngine on
RewriteRule ^404.html$ 404.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.phpTaken from:easymodrewrite:The [L] flag can have unexpected results if you are not clear on how the module behaves. Note that the following only applies when mod_rewrite is used in a .htaccess file. The [L] flag behaves exactly as expected when used in httpd.conf.The L flag will tell Apache to stop processing the rewrite rules for that request. Now what is often unrealised is that it now makes a new request for the new, rewritten filename and begin processing the rewrite rules again.Basically, you have to tell the second rule not to match existing files (404.php is a real file, not dynamic).Hope this helps someone. | This seems so simple, but I can't figure it out... I would like all requests to be rewritten to index.php (which will interpret the request)apart from404.html which should be rewritten directly to 404.php.The following code does work at rewriting everything to index.php, but 404.php never gets triggered.I have left line 3 commented because I don't know what it does.Options +FollowSymlinks
RewriteEngine on
#RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^404.html$ 404.php [L]
RewriteRule ^(.*)$ index.php [QSA]As you can see, my needs are very simple, but so is my brain! Please help!Thanks.EDITThis line works fine on its own:RewriteRule ^404.html$ 404.phpbut when the other RewriteRule is introduced, everything gets forced through index.php - even 404.html...... (I tried changing the order too). | Simple RewriteRule question |
I think the problem is that after Apache rewrites /news to /subdirectory/news it then finds itself with a request matching a directory on the filesystem, which does NOT end in a trailing slash. So it issues a redirect to a new url including the trailing slash.The thing is, we do actually want the traling slash to be added to preserve the canonical url (otherwise we end up with /news and /news/ leading to the same place - not good for relative links, SEO etc.), just not quite in the way apache is doing it. So we have to do it ourselves, by adding the following:RewriteCond %{REQUEST_URI} ^/subdirectory/.*[^/]$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdirectory/(.*)$ /$1/ [L,R=301]The conditions of this rule will match any requests that begin with 'subdirectory', DO match a directory on the fielsysem but do NOT end with a trainling slash. (e.g. '/subdirectory/news'). The rewriterule then issues a permanent redirect to the same path, but ending in a slash and with 'subdiretcory' stripped out (e.g. '/news/').The client will then issue a request for '/news/', apache will rewrite this to /subdirectory/news/ and will not issue a redirect becuase it ends with a slash.Quickly tested this out and it seems to do the trick. | I want to have my primary domain be hosted from a subdirectory (have completed this step somewhat), i.e. when someone types in www.example.com/news behind the scenes it will go to www.example.com/subdirectory/news but will still show up as www.example.com/news.I have used the following bluehost code to accomplish this:RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdirectory/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/index.php [L]This code works if I type in www.example.com/news/ (notice the trailing slash) but does NOT work if I just type in www.example.com/news (without the slash). Any ideas why?Thank you. | Subtle htaccess problem. I am going insane |
The first RewriteCond checks the HTTPS flag set by the server (Check thislink. Scroll to Server Variables).The second RewriteCond checks an environment variable, which could be set by a prior RewriteRule (SeeSetenvvarsfor setting an environment variable).Did you try using %{HTTPS} !=on?RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]Note: Both links refer to the apache documentation. Depending on your used HTTP Server this might not work. | Could you explain the difference between the two .htaccess redirects below?The first redirect is the one I tend to use the most but it didn't work on a recent site (too many redirects – even though I didn't have any set up) but the second redirect worked and I'm curious.RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteCond %{ENV:HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] | .htaccess redirect – differences between two redirects |
Do this in .htaccessRewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /maintenance/index.php [L,QSA]Anyone visits some link on your website will be redirected to:www.yourwebsite.extension/maintenance/index.php | Website will be going down for maintenance very soon. In the mean while all visitors will be redirected to a page indicating that the website will be down for a short period of time until maintenance is complete.If I wanted to redirect all traffic that doesn't match my IP to this page located within themaintenancedirectoryhttps://example.com/maintenance/index.phpWould these rewrite rules be valid and/or work for what I'm trying to accomplish?RewriteCond %{REQUEST_URI} !/maintenance/index.php$
RewriteCond %{REMOTE_ADDR} !^192\.192\.192\.192$
RewriteRule $ /maintenance/index.php [R=302,L] | .htaccess redirect to file within directory |
I think I know what you are trying to do, in which case I think this will work but I haven't tested it (apply for other iframes and domains as you see fit).site 2/3/4.comif (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == 'http://domain1.com') {
include_once('sidebar.php');
} else {
header('Location: http://domain1.com');
}site1.com<iframe src="http://domain2.com" frameborder="0"></iframe>I may have got the requirements wrong, but this should show your sidebar content if there is a referrer, and if not, it will redirect to domain1.com.A more robust way (in case the referrer is not populated for some reason) might be to add a url parameter to the iframesrcattribute, e.g.<iframe src="http://domain2.com?iframe=1" frameborder="0"></iframe>and then check for thatif (isset($_GET['iframe']) && $_GET['iframe'] == '1') {
include_once('sidebar.php');
} else {
header('Location: http://domain1.com');
}but that is also easily manipulated, a better way may be to come up with a token/hash to use instead. | Can anyone please help me? I have these websites: domain.com, domain.com/site2, domain.com/site3,and site4.domain.com. Site 1,2 and 3 are wordpress and site4 is php website. In site 1(domain.com) I create a side panel and my goal is that when a user accesses all my sites they still can use my side panel, so I embed/iframe site2,3 and 4 on page site 1 using advance iframe pro. How do I make site 2,3 and 4 only can open or access from site 1? For example, I iframe/embed site 2 in domain.com/mypage so that when a user opens domain.com/mypage, site 2 will open via iframe. But when a user accesses direcly from domain.com/site2, they will redirect to site1(domain.com/mypage) or they only see blank page.
I tried to modify .htaccess as follows:{
order deny,allow
deny from all
allow from domain.com/site2/12345
}and in iframe:[iframe src="domain.com/site2/12345"]but its not working. When I access direcly using url domain.com/site2 it shows 404 on site1, and when I access directly domain.com/site2/12345 it can open site2, but in iframe it shows 404 site1... (not use https:// whe use https:// it show 404 site1 but when only use www.domain.com/site2/12345 it can open site2) | how to website only can access from iframe |
Make sureAllowOverrideis set to FileInfo (or All):AllowOverride FileInfoinside the relevant directory.Also it might be possible that the environment variables were removed by suexec. | I have set some variables in .htaccess file withSetEnvbut it's not getting by php file using$_SERVER.Here is the code of htaccess:RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
AddDefaultCharset utf-8
# Enviroment variables; change these to match server configurations
SetEnv ENVIRONMENT development
SetEnv APP_DB_HOSTNAME localhost
SetEnv APP_DB_USERNAME root
SetEnv APP_DB_PASSWORD root
SetEnv APP_DB_NAME root_pro
SetEnv APP_ENC_KEY xxxxx-xxx-xxxBut I didn't got the value in$_SERVER['ENVIRONMENT']. Please give advice on it please.Note: This is not working in my live server and there is alreadymod_envalready enabled.Thank you in advance. | Not getting value in $_SERVER from SetEnv variable in htaccess |
If you need to redirect such a single page or point it to a specific new location, use such rule (the same as above just specifying exact URL):RewriteEngine On
Redirect 301 /xxx-index.html http://www.newdomain.com/help/xxx-index.phpApache mod_rewrite manual has a page:When NOT to use mod_rewrite. This particular scenario is listed there (Redirect is much lighter that RewriteRule in terms of resources, which can be an issue on very busy servers). | I tried to redirect using this method via htaccess but there is no redirection is occured.
Please correct me if there is any mistake.Redirect 301 /subfolder/page-url https://mydomain/subfolder/new-page-url | How to Redirect 301 /subfolder/page-url https://mydomain/subfolder/new-page-url |
That "statement" isn't necessarily highlighting a current problem with your site.
Providing you are consistently linking tohttp://example.com/throughout your site and not mixing this withhttp://example.com/index.htmlin other places.Adding arel="canonical"tag, pointing to the canonical URL (as you suggest) is sufficient to avoid anypotentialSEO problems.However, implementing a 301 redirect from/index.htmlto/in.htaccesswould be a "belt & braces" approach. If you have a "simple HTML page" (ie.notWordPress) then you can do this in a single mod_rewrite directive in.htaccess:RewriteEngine On
RewriteRule (.*)index\.html$ /$1 [NS,R=301,L]TheNSflag prevents this rule being processed for subrequests (which is what prevents a redirect loop in this instance). | I'm having difficulty fixing this problem:
I ran an SEO test (on sitechecker.pro) on my portfolio, and it gave me this problem that I can't figure how to fix:Search engines see yourhttp://gvdavidtran.comandhttp://gvdavidtran.com/index.html(orhttp://gvdavidtran.com/index.php) as different pages. With a variety
of URLs, it's more challenging to get consolidated metrics for a
specific piece of content.I tried:Adding a canonical link in the index.html file so it refers tohttp://gvdavidtran.comVerifying permissions with Google Search Console, but I'm not sure if that helps, because it may only fix on Google and not other search engines.Would adding an .htaccess file help, or is it only for Wordpress/php? I'm not sure what else to do to fix it.My website is a simple html page, not a Wordpress.First time asking a question here, thanks! | Domain root and index.html seen differently by search engines |
This one regex may helppreg_replace("/testblog1\.php\?id=\d*&title=/", "$1", $input_lines);Sohttp://www.eyecatchers.co/testblog1.php?id=123&title=your-titlegoes ashttp://www.eyecatchers.co/your-title | I want to remove id from URL and rewrite it with domain followed by title name only for SEO-frendly URL.http://www.eyecatchers.co/testblog1.php?id=110&title=6-Benefits-of-Hiring-a-Digital-Marketing-Agency.This is my current URL and I want to rewrite it through.htaccessto following URLhttp://www.eyecatchers.co/6-Benefits-of-Hiring-a-Digital-Marketing-Agency.I have tried with<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule id/(.*)/(.*)/ testblog1.php?id=$1&title=$2
RewriteRule id/(.*)/(.*) testblog1.php?id=$1&title=$2But it has given mehttp://www.eyecatchers.co//id/110/6-Benefits-of-Hiring-a-Digital-Marketing-Agency.How can I get domain along with title name only? | How to remove id and title from url and rewrite it with domain followed by title name only? |
You need to direct your VHOST to laravel's public folder. This is done for security purposes. Ideally your laravel install is outside the public folder, thus you would have yourdomain.com contain your laravel install and rename your public folder to swap.IF you really want the name swap in your routes you could use route prefix with groups. | I've finished my laravel project and played it in a subfolder on my domain.https://example.com/swapSo the above is the root of my directory and when I go there, I do get the index. But now every link I press, I'm redirected to the root of my domain. So I'm getting:https://example.com/events/1Instead ofhttps://example.com/swap/events/1Am I forced to change all URLs by hand in my files are is there a way my htaccess can always redirect to this 'swap' folder and place everything behind that?I've tried using groups in my routes, without success. | Laravel URLs not working in subfolder |
+50Try with:RewriteEngine on
RewriteRule html search.php [NC,L]If it does not work, you have another problem in .htaccess (Please indicate it in full in your question) or config.Start by clearing your cache before testing. Or try with another browser. | I have a URL likeexample.com/product-name.html.I want to redirect any URLs that contain the stringhtmltosearch.phpbut I want to keep the original URL that was typed in, so ifexample.com/product-name.htmlwas redirected tosearch.phpit should still showexample.com/product-name.htmlin the browser.I am using:RewriteCond %{REQUEST_URI} html
RewriteRule .* search.phpWhich redirects but does not keep the original typed URL in the browser.How can I do this? | htaccess if URL contains string redirect to page without changing URL |
That jQuery code only disables the browser's context menu. It doesn't stop anyone from downloading the video in any way other than through that menu.Using token authentication is useful to stop users sharing the link, but won't stop a download extension from downloading the URL from the same session, as the token is still valid.A segmented format such as HLS or MPEG-DASH is harder for the casual user to download, but there are probably download extensions that will be able to convert them to MP4. DRM (which Video.js supports) is the most secure, but obviously comes with a high overhead of cost and complexity. | I'm working a script which need to restrict video download for users, they only allow to watch online,I'm currently use "video.js" script for the player,I already restricted right click function,jQuery('.video-js').bind('contextmenu',function() { return false; });also added dynamically load videos likehttps://exmaplle.com/loadvid.php?video=fire.mp4&seskey=1a2asasd125asdasdasdasdasbut when i check using some FireFox extensions. those give ability to download the video file.Is there anyway to prevent download videos using browser extensions, or are there have another players which support secure video play. | Disable video download on VideoJS script |
try to move .htaccess file to root directory | I am learning the slim framework. I got a point where I have to set up my webserver such that I can see something likehttp://slimappinstead ofhttp://localhost/slimapp/public/index.php.I have included a .htaccess file in the public folder of my project like soRewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]I have also set up a virtual host on my wamp server<VirtualHost *:80>
DocumentRoot "C:\wamp64\www\slimapp\public"
ServerName slimapp
<Directory "C:\wamp64\www\slimapp\public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>I have also added this to my hosts file127.0.0.1 slimappI restarted my server but I get a 'Not Found' error when I try to access my routes."Not Found
The requested URL /hello/uche was not found on this server."This is my index.php file<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();Please help me here. | Routes not working on Slim framework |
The following regular expresion will match any number of\followed by a stringnotcontaining a dot. Then will not match the url will html extension.^(/[\w-]+)+$View regex state diagram | I have an old website that has URL's like:/my-category/my-productand in my new website, I've managed to keep the 'category' part the same in a lot of case (but not all), but I want to redirect their old products that don't have the .html suffix to the category.So/my-category/my-productwill get redirected to/my-category/but/my-category/my-product.htmlwill be ignored as it has.htmlon the end. The new website products have.htmlon the end, where the old website doesn't.I also need to stop further rules processing. | Redirection of URL's without a .html Suffix |
Try with a configuration that looks like this in your.htaccessfile :<IfModule mod_rewrite.c>
RewriteEngine On
# ... Your other stuff
# RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.*)$ /app_MYNAME.php [QSA,L]
</IfModule>Also, make sure that your nginx/apache host file is pointing to the web directory of your Symfony project. | i want to add another app_MYNAME.php in the web folder.
This file is nearly identical to the app.php.
The only difference is this entry:$kernel = new AppKernel('MYKERNELNAME', false);I want to load different configuration files with these method.When i type in the browser:domain.de/app_MYNAME.php/VALUEall is fine.Now i want to hide theapp_MYNAME.php. The Result should look like:domain.de/VALUEThe second step is the redirecting. When someone type in the browser:domain.de/MYNAME/VALUEit should be redirected to:domain.de/app_MYNAME.php/VALUEI only get a404or amisconfiguredmessage.At the end i need 3 app_MYNAME.php files (app_MYNAME1.php, app_MYNAME2.php, app_MYNAME3.php).I hope someone could explain me, what to put in the .htaccess file.Here is my .htaccess file:DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule> | Symfony .htaccess adding rule for app_MYNAME.php |
You can do it like that, many used Bolt 2 that way. But of course, it's more secure when you move some parts out of the web accessible folder. But for that, I would suggest using Bolt with a subdomain like blog.yourdomain.com. | I installed (via FTP) Bolt CMS only for a blog section of a website as I don't want to re-create the entire site in Bolt, just add a blog. I did this by adding all of Bolt's files in a folder www.mysite.com.au/blog and used the index page of Bolt as the blog page. It all works perfectly, however I am now concerned because I was reading through Bolt's documentation and it says to move the core Bolt files outside of 'public' for security, but the instructions don't cover the situation of wanting to keep Bolt separate from the rest of the site. My structure looks like this:cache
etc
logs
mail
public_html
root
ssl
www
-index.php
-page1.php
-page2.php
-BLOG (Bolt folder)
--extensions
--files
--theme
--vendor
--src
--appIs this a security risk? Should I move the Bolt extensions/vendor/app folders up above www, will that break anything? I am new, so if I wrote anything wrong or missed details please let me know. Thanks in advance! | Installing Bolt CMS within a subfolder |
You should try something like this :RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .htmlBut it's better to add it in your vhost or if it's possible, blogbally in your apache2.conf. | I have a html site and I want html pages to be parsed as php; I'm using a htaccess file for that.On the online server, it works properly. The command is:AddHandler application/x-httpd-php5 .html .htmHowever, on localhost server it doesn't work at all. When I access the page, it prompts to download the file instead of displaying the page.I'm using PHP 5.6.3 and PHP as module, I guess.I tried all sorts of similar commands in htaccess, like:AddType application/x-httpd-php .html .htmAddType application/x-httpd-php5 .html .htmAddHandler application/x-httpd-php .html .htmAddHandler application/x-httpd-php5 .html .htmAddHandler application/x-httpd-php .html .htmAddHandler application/x-httpd-php5 .html .htmAddHandler x-mapp-php .html .htmAddHandler x-mapp-php5 .html .htmbut no luck.I also triedRemoveHandler .html .htmbut without success.I checked the httpd.conf file and among others, there are the following:LoadModule php5_module "C:/Program Files/PHP/php5apache2_4.dll"
AllowOverride All
<Directory "D:/mysites/">
AllowOverride All
Require all granted
</Directory>Where should I look for anything wrong then..?Any hint appreciated. | parse html as php with htaccess prompts to downloading |
Just try:RewriteRule ^/?product\.tmpl$ /product.php [L,QSA]Modifier QSA keeps the query string whatever it is:http://httpd.apache.org/docs/2.4/rewrite/flags.html#flag_qsa | I'm trying to redirect a numerous amount of 404s.
Some old sites linked tohttp://example.com/product.tmpl?SKU=XXXwithXXXbeing the numerical SKU number.I want it to redirect tohttp://example.com/product.php?SKU=XXXThis is where I've gotten to but it still isn't working. Do I have a typo in my code?RewriteEngine On
RewriteCond %{QUERY_STRING} ^SKU=([^&]+)
RewriteRule ^/?product\.tmpl$ /product.php?SKU=%1 [L,R=301]EDIT: My full htaccess file reads as follows:RewriteEngine On
RewriteCond %{QUERY_STRING} ^SKU=([^&]+)
RewriteRule ^/?product\.tmpl$ /product.php?SKU=%1 [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress | htaccess Redirect with Variable carried over |
You can setup your own domain name with herkoku by following the steps listed herehttps://devcenter.heroku.com/articles/custom-domains | I am trying to set up my blog to be displayed in a page instead of a subdomain. So if a post is post-1, I want the following:blog.mydomain.com/post-1 --> mydomain.com/blog/post-1The problem is that my app is a node app on Heroku and my blog is a wordpress. I looked at modifying thehtaccessbut if I am not mistaken, htaccess is only for PHP.
Could somebody point me in the right direction ? | virtual host for node app on heroku |
create a pi.php file with just the code:<?php phpinfo();in it and save it in the same folder as your Magento, then access via browser.The value that will be displayed for max_input_vars (local column) is your run-time value. If it differs from your setting in php.ini, you're probably changing the wrong INI file.Mod_FCGID can use a differenct file from the "classic" /etc/php.ini, or settings in any of the files in /etc/php.d/ - for instance - may override the ones in the "global file".phpinfo() shows the list of parsed INI files, so you can see which to amend.PLEASEremember to take off the file once you have fixed the issue: it's a likely security threat, as you show a lot of details that may be useful to hackers. | I'm running Magento, and I am receiving "mod_fcgid: stderr: PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0" when trying to save Related Products with 5000+ products in the DB.Most people recommend trying to fix this by updating the max_input_vars to something higher. I went ahead and added max_input_vars = 100000 to php.ini, and added php_value max_input_vars 100000 to .htaccess for good measure.php.ini is being updated, when I run php -i | grep max_input_vars it outputs max_input_vars => 100000 => 100000I also tried smaller numbers like 5000, 6000 (in case for some reason 100000 is too high)I did remember to restart apache2, so that is not the issue.No matter what I do, I still receive "mod_fcgid: stderr: PHP Warning: Unknown: Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0"Any ideas? | Receiving "Input Variables Exceeded 1000" error even after updating max_input_vars |
I've solve this issue using this way<?
$request_uri=explode('/',$_SERVER['REQUEST_URI']);;
$lang_code=$request_uri[1];
$page_code=$request_uri[2];
?>Forde/articles/listall.htmlyou will get$lang_code=deand page code:$page_code=articlesand then you can include content from the exact lang file:include('.$page_code.'/content_'.$lang_code.'.php');Real path for content are:articles/content_de.php
articles/content_en.php | I have this url's for multi language system using php :http://mydomain/ <-- default language english (en)
http://mydomain/index.php?lang=de
http://mydomain/index.php?lang=fr
http://mydomain/index.php?lang=trNow, for another page i have this url:http://mydomain/article.php?id=xx <-- show article details
http://mydomain/article.php?list=all <-- show article archive
http://mydomain/gallery.php?id=xx
http://mydomain/faq.php?id=xx
http://mydomain/faq.php?list=all
http://mydomain/contact.phpNow, i need to create seo friendly url using php and htaccess Like This :for index:http://mydomain/ <-- for default
http://mydomain/de/
http://mydomain/fr/for article ie:(domain/lang/id/title.html)http://mydomain/de/articles/22/test.htmlfor page:http://mydomain/de/contact.htmlfor archive:http://mydomain/de/articles/listall.htmlin htaccess i write this code for article :RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^articles/([0-9]+)/([A-Za-z0-9-]+)/?.html$ articles.php?id=$1but this worked for one language not multiple language. how do can i create seo friendly url for multi language system?! | generate seo friendly url for multi language system using php .htaccess |
You may do so, after one status (you may manipulate its number) provided to the client, and then use fail2ban with a jail for a long period having blockaction being set to drop. Fail2ban would add the blocked ip to the firewall iptable. | I'm trying to set up an .htaccess rule, that, upon a certain file being requested off the server, will completely drop the connection if the rewrite condition is met.I don't wanna just deny the connection and send any HTTP status code in response - I want to set it up in such a way that the connection will simply be dropped with no response whatsoever when the condition is met. No 403s, no redirects, nothing. Pretty much as if the request is blocked by a firewall.How would I go about doing that, and is it doable with .htaccess? | .htaccess rule to drop the connection without any response |
I went ahead and contacted namecheap directly and they corrected it quickly - I don't think there's anything you can do. Specifically, they said:We have whitelisted Mod Security rule which has been triggered. Please try preform necessary actions one more time.Hope that helps. | I want to disable comments site-wide on a Wordpress site, but I keep getting this one annoying problem.I've looked around and all of the results are for older versions of Wordpress. I have a fresh install of Wordpress 4.0 onto a namecheap hosting server.When I try to disable comments in Settings > Discussion by unchecking the box and clicking on the submit button below, I get redirected to a page that says:You don't have permission to access /wp/wp-admin/options.php on this
server.Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.One suggestion from a few threads from 5-7 years ago was to modify the .htaccess and permissions. I tried, it still is returning the same error. Those suggestions were for older, less secure versions of Wordpress, so I'm thinking there should be a different workaround for 4.0. I also for some reason don't have SSH access to the server, probably because of some stupid namecheap / cpanel restriction. | 403 error in Wordpress 4.0 options.php |
Instead of using ErrorDocument in the htaccess configuration, you could force a real redirect to the error.php like this:RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /error.php?pg-name=%{REQUEST_FILENAME} [L]Source:How to get `$_POST` query when 404 redirected through .htaccess?In the error.php page you can then check, if the pg-name parameter is given to the error.php:echo '<pre>';
print_r($_GET);
echo '</pre>';If you call you page like this:http://domain1.com/asdasdasd(assuming the link is not found), the output from the error.php will look like this:Array
(
[pg-name] => /path_to/public_html/asdasdasd
)Then you can get to the requested string "asdasdasd". | Is there any to to capture query string and append it to error document (404). Something like:Requested page:http://www.example.com/sdsdsdRedirect to:http://www.example.com/404.php?pg-name=sdsdsd | how to append a query string to error document |
can you please try this code in the htaccess file..RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]this one works fine at my instance... | I am not to clued up on these and I'm struggling to get this one working.I just keep getting 404 errors, can someone give me a hand?RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]This is what I have so far. I'm using the CodeIgniter framework. | My htaccess file keeps bring up 404 errors |
Specify the portin your rule. Change your .htaccess to something like:RewriteCond %{QUERY_STRING} ^(.*)userid=fakepass(.*)
RewriteRule ^(.*)$ https://%{HTTP_HOST}:9000/somedirectory/request.jsp?userid=theuser&password=realpass | I'm using Apache mod_proxy with mod_rewrite to mask some credentials in the query string. The logs show that the rewrite rule is working properly, but the port number (:9000) is being stripped causing the proxy to reject the URL. Aside from security lectures and anything else irrelevant to the actual question at hand, can anyone tell me what the solution might be?Basic example using:RewriteCond %{QUERY_STRING} ^(.*)userid=fakepass(.*)
RewriteRule ^(.*)$ $1?%1userid=realpass%2Original URL:https://domain.com:9000/somedirectory/request.jsp?userid=theuser&password=fakepassIntended URL::https://domain.com:9000/somedirectory/request.jsp?userid=theuser&password=realpassActual result after mod_rewrite:https://domain.com/somedirectory/request.jsp?userid=theuser&password=realpass | Why does mod_rewrite strip the port number from my request url? |
Ifwww.somesite.comis hosted on the same server that the rule is being applied on, then it's network traffic is never leaving the server. That means a 3rd party not on the server won't be able to "eavesdrop" the contents of the request and response (or masquerade as a trusted party) so it doesn't matter if it's unencrypted. The assumption here is that if someone can get access to this traffic, they've already compromised the server so the reverse proxy may be the least of your worries. | Say I have an url that is served over HTTPS, but in my .htaccess I rewrite proxy it to another domain that is on the same server like so:RewriteRule /https-url/(.*) http://www.somesite.com/$1 [P,L]Is this a secure situation? I would assume it is, because the browser is communicating with an SSL secured url and the rewriting is done on the server where nobody can interfere.EDIT:I just went on and tried it. It works just fine, you can just redirect people to https if they approach the http url directly. This has also saved me some money since I only had to buy an SSL certificate for one domain. | Is it secure to rewrite proxy a https url to http? |
It looks like you might be over-escaping inside the second character class.Check out the accepted answer to this SO question:htaccess regexp Underline and Space doesn't workNot knowing what the goal of this RewriteRule actually is makes it difficult to offer any further help. I would recommend looking into the RewriteRule flags to see if there is something useful you can leverage there, such as the noescape flag [NE]:http://httpd.apache.org/docs/current/rewrite/flags.html | I need to use # in this regular expression but it make commented all characters after it ( #)RewriteRule ^([a-zA-Z0-9_-]+)?/?([a-zA-Z0-9@#$&%_"'\{\}:\,\-]+)can some one help me how can I use # not for comments...I used # but it doesn't work
thanks for any help. | how to use # in reqular expression in pup htaccess file |
Your .htaccess doesn't protect for anything else than admin*.If you have auto index option enabled for example, it doesn't match the pattern (but having DirectoryIndex set to adminindex for example do so).Maybe the authentication prompt is related to a resource needed by the page (JS, css, image, favicon) and not the page itself.Could you try to inspect HTTP response using curl or apache logs ?This might give you a hint.curl -vso/dev/null http://localhost/test/ | in my htaccess I have below code which is used to save admin* area.
If I give wrong username password it keeps poping up for correct usrename but if I press cancel I can see my restriced area instead loading error page, what is wrong? thanksAuthName "Restricted Area"
AuthType Basic
AuthUserFile /home/mydirectory/.htpasswds/.htpasswd
AuthGroupFile /dev/null
<Files admin*>
require valid-user
</Files> | htpasswd is bypassing when click cancel |
Had you considered using some variety ofDynamic DNSinstead? That would let the IP addresses change frequently while maintaining the same DNS names. | I am looking for a generalized IP canonicalization solution that would not hard code IP address in my htaccess file. I generally run my applications on amazon EC2 instances and IP addresses frequently change. I'd hate to have to manually update htaccess every time it does so. So specifically, I am looking for htaccess rules that would match pages accessed via ip address and perform a 301 redirect to the actual domain. | Generlized IP Canonicalization Solution Within .htaccess |
Here is a very basic example, but that's how you can do it.<Directory /srv/dev/>
AllowOverride All
Options +Indexes
AuthType Basic
AuthUserFile /srv/.htpasswd
Require valid-user
</Directory>
<Directory /srv/dev/apps/>
<If "%{REQUEST_URI} != '/'">
Require all granted
</If>
</Directory> | i have this directory structure on my web server:web
privatedir1
privatedir2
publicdir
file1
file2
file3i want to set the following functionality using .htaccess files:user 'admin' (authenticated) has unlimited access to all dirs (incl. dir indexes)anyone else can download file1, file2, file3 but can not see listing (index) of publicdircan you please describe how to achieve this with .htaccess files?
i know how to allow/disallow directory indexes but i can't figure out how to do it conditionaly (depending on whether the user is authenticated or not)thank you very much. | apache .htaccess show directory index only to authenticated user |
You should not escape the forward slash. Try this:RewriteRule ^news/([0-9]+/.*)\.jpg$ /image.php?img=$1 [L] | It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed11 years ago.I am attempting to rewrite URLs like the following:domain.com/news/12/imgname.jpgtodomain.com/image.php?img=12/imgnameI am using the following in my .htaccess file, but it does not seem to be working:RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^news/([0-9]+\/.*)\.jpg$ image.php?img=$1 [L]Can anyone help me see what I've done wrong? | .htaccess rewrite imgname.jpg to image.php?img=imgname [closed] |
To internally rewrite/someAddressto/index.php:RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^page=([^&]+)&id=([^&]+)$
RewriteRule ^/?([^/]+)/$ /index.php?page=%1%id=%2&siteAddress=$1 [L]To externally redirect/index.phpto/someAddress:RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?page=([^&]+)&id=([^&]+)&siteAddress=(^[&\ ]+)
RewriteRule ^ /%3/?page=%1&id=%2 [L,R=301] | I would like it to show the url/index.php?page=somePage&id=someID&siteAddress=someAddressas/someAddress/?page=somePage&id=someID.How can I use the rewrite rule for this? | How do i rewrite this url using .htaccess |
If you removeRewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-dit appears to work as expected, because any request to the right url will not be rewritten.you might want to add[L]as a flag to signify it's the last rewrite rule, like so:RewriteCond %{REQUEST_URI} !^/~username/
RewriteRule ^(.*)$ /~username/$1 [L] | Situation:I'm moving a website from a production environment to a test environment.The test environment url is similar tohttp://192.168.1.100/~username/There are thousands of files which use the following within the html<img src='/images/image.jpg' />Since the request is going to roothttp://192.168.1.100/the files are 404.Rather than finding and replacing all of html I'd assume that there is an easy way to fix it with mod_rewrite via .htaccess.I've tried using the followingRewriteCond %{REQUEST_URI} !^/~username/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~username/$1But did not work as expected.Thanks in advance.UPDATEThe development environment resides within cpanel/whm. So when the username is removed from the requested url, it now belongs to the root users. So, my question now: How do I update the .htaccess file for the root user to mod_rewrite back to the ~username? | .htaccess. Redirect requests to ~username folder |
Per your comment:I have set this additional code to make sure the session cookie is in
right path and domain. ini_set('session.cookie_domain',
'.bostonairporttaxicab.com'); ini_set('session.cookie_path',
'bostonairporttaxicab.com/';);I think your cookie_path is wrong. It should not contain the domain name, as the path is the part trailing the domain name. Try setting it to/and see if that fixes it. Maybe Chrome is interpreting it differently than the other browsers, and therefore rejecting your session cookie. | My project hangs on this single issue.I have this code in my htaccess to implement a flat url systemOptions +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/page.php
RewriteRule (.*) page.php?pid=$1 [QSA]While this code exists I cannot access session variables created on one page on any other page. Even if the pages are static .php pages that do not go through the redirection the sessions disappear. ONly this code somehow prevents sessions.I have set session cookie path and domain to make sure the realm is correct, but it does not work.Any help will be appreciated from the bottom of my heart.The funny thing is it only fails on Chrome. | PHP Sessions disappear on htaccess redirect condition - In Chrome only |
I'm assuming you have a/mrmikeanderson/folder where the 2nd htaccess file is. The reason why theRewriteRule ^$ index.php?page=homeisn't being applied is because you are redirecting the/request tomrmikeanderson/index.php. So either change this rule:RewriteRule ^(/)?$ mrmikeanderson/index.php [L]toRewriteRule ^(/)?$ mrmikeanderson/index.php?page=home [L]or change this rule in the other htaccess file:RewriteRule ^$ index.php?page=hometoRewriteRule ^(index.php)$ index.php?page=homeOr you can change yourindex.phpfile to assume the variablepageishomeby default. | I have one .htaccess file in the public_html folder of my server that lets me keep my primary domain in a subfolder:RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mrmikeanderson.com$
RewriteCond %{REQUEST_URI} !^/mrmikeanderson/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mrmikeanderson/$1
RewriteCond %{HTTP_HOST} ^(www.)?mrmikeanderson.com$
RewriteRule ^(/)?$ mrmikeanderson/index.php [L]In that subfolder is another .htaccess with more rewrites to turn urls ending with things like /index.php?page=about into just /about:RewriteEngine On
RewriteRule ^$ index.php?page=home
RewriteRule portfolio index.php?page=portfolio
RewriteRule resume index.php?page=resume
RewriteRule about index.php?page=about
RewriteRule contact index.php?page=contactThe last four pages work, but my rewrite for just the domain name (\^$) is broken. Everything works on my local MAMP server, but the first .htaccess file is not present there, so I'm thinking that the two are conflicting. Any web dev champs able to see what's going wrong? | .htaccess files possibly conflicting? |
Figured it out - looks like my use of the * in the first two rewrites was trumping my final rule... long story short, here is the code that works correctly (changed * to + in three places):RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]+)/([a-zA-Z0-9\-_]+)$ /content.php?a=$1&b=$2&c=$3
RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]+)$ /content.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9\-]*)$ /index.php?a=$1 | I've got my htaccess rewriting on the following rules:RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]*)/([a-zA-Z0-9\-_]*)$ /content.php?a=$1&b=$2&c=$3
RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]*)$ /content.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9\-]*)$ /index.php?a=$1that works wonderfully when i go to "mydomain.com/nameofpage"but when i add a trailing slash "mydomain.com/nameofpage/" the browser adds "index.php" to the end and 404's me.Thoughts?Thanks!EDIT.
Figured it out.looks like my use of the * in the first two rewrites was trumping my final rule... long story short, here is the code that works correctly (changed * to + in three places):RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]+)/([a-zA-Z0-9\-_]+)$ /content.php?a=$1&b=$2&c=$3
RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]+)$ /content.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9\-]*)$ /index.php?a=$1 | htaccess rewrite adds "index.php" when I add a trailing slash to an address |
As per @Gerben's comment...Adding<!--does not work. The host already starts their extra stuff with a comment, and the-->that follows gets overridden.Addingheader('Content-Type: text/xml');does nothing, the javascript still shows.HOWEVER! We've found the answer... puttingexit();at the end of the PHP script will disable this function!As a side note to Mr. @Gerben -- Thank you, and I've voted up one of your other answers, so you get credit for this... | My free webhost appends analytics javascript to all PHP and HTML files. Which is fine, except that I'm using nuSoap to create a WSDL file for a webservice I'm working on. My darn host adds this to my php-generated WSDL file.Some people have suggested add this to the .htaccess file:AddType text/xml .phpWhich is dandy, but it disables the PHP engine as well, and there's no way to generate the WSDL then.I've searched everywhere, no luck. Webhost does not respond to emails or support tickets either.Edit: The script my webhost uses is Histats. Published by Histats.com. Also, this JavaScript block falls outside the<html></html>tags and won't pass validator. | Disable Statistics/Analytic Javascript |
Try the following in your .htaccess fileRewriteEngine On
RewriteBase /
#if it starts with routes a-b then send to yyy
RewriteCond %{REQUEST_URI} ^/(a-b/.*)$ [NC]
RewriteRule . http://www.yyy.com/%1 [R=301,L]
#if it does not start with an a, then also send to new site
RewriteCond %{REQUEST_URI} !^/a [NC]
RewriteRule (.*) http://www.yyy.com/$1 [R=301,L] | I'm migrating a website from, let's sayexample.comtoyyy.com.Butexample.com/a, and everything likeexample.com/a/*should stay atexample.com.But there's something more: I have routes called something likeexample.com/a-b/*, and this should be redirected toyyy.com/a-b/*(like the rest of the website).I'm able to get the website to correctly redirect everything exceptexample.com/a*, but this meansexample.com/a-bis not redirected...I tried to write the following rules in my .htaccess, in vain:RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^a$
RewriteCond %{REQUEST_URI} !^a\/.*$
RewriteRule ^(.*)$ http://www.yyy.com/$1 [R=301,L]or even:RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^a-b
RewriteRule ^(.*)$ http://www.yyy.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^a
RewriteRule ^(.*)$ http://www.yyy.com/$1 [R=301,L](Changing my route name is not an option) | Rewrite Rule to redirect the whole website except one route |
Something like this maybe?RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/index.(php|html?)
RewriteRule ^(.*)$ profile/company-profile.php?cid=$1 [NC,L] | In my page, when I write the url domain.com/abc it uses the htaccess RewriteRule ( posted below) and opens the company-profile.php page, showing the ABC profile.ABC IS AN EXAMPLE. IT MAY BE ANYTHINGHowever, even I have a domain.com/index.php file, when I write just domain.com and hit enter, it takes me to thecompany-profile.phppage where it supposed to show theindex.phpfileMy question is how can I fix this ?RewriteEngine On
RewriteRule ^([a-z0-9]+)?$ /domain.com/company-profile.php?cid=$1 [NC,L] | Rewrite Rule don't let me access my domain's index.php |
See my answer here:my .htaccess redirection failsYou'd rewrite it like this (leaving out the title - you'd need php for that):RewriteEngine On
RewriteCond %{REQUEST_URI} ^/books\.php$
RewriteCond %{QUERY_STRING} ^([a-z])=([a-zA-Z0-9_-]+)$
RewriteRule ^(.*)$ http://www.domain.com/%1/%2? [R=302,L] | I currently use the following rewrite rules:RewriteRule ^books/([bc])/([0-9]+)/(.*)/page([0-9]+) books.php?type=$1&id=$2&title=$3&page=$4 [L]RewriteRule ^books/([bc])/([0-9]+)(.*) books.php?type=$1&id=$2&title=$3 [L]RewriteRule ^books/(.*) books.php?type=$1 [L]RewriteRule ^books books.php [L]What I'd like to add, either using htaccess or PHP, is a redirect from a standard URL format to an SEO URL format.For example:books.php?b=1=>books/b/1/book-titlebooks.php?c=1=>books/c/1/category-titleIf this can be done using htaccess it's fine, I don't absolutely need the title, I handle the title using PHP anyway (to redirect to the correct URL in case the title that's entered is incorrect).Thanks. | PHP Redirect standard URLs to SEO URLs |
Although I was initially searching for a mod-rewrite solution I have figured out a way to achieve the same by modifying the (core) Joomla! router.On line 47 of includes/router.php after:$path = substr_replace($path, '', 0, strlen(JURI::base(true)));I added the following:$subpages = array("trends","other"); //Add URL segments you want to reroute
foreach ($subpages as $subpage):
if (strstr($path, "/".$subpage)) :
$path = str_replace("/".$subpage, "", $path);
$vars['show'] = $subpage;
endif;
endforeach;Now when loadinghttp://www.website.com/local/amsterdam/trends, this URL is displayed while the pagehttp://www.website.com/local/amsterdamis actually loaded with the ?show=trends parameter.For me this a more flexible solution than using mod-rewrite even though a core file is modified. You might want to use some conditional statements to only run this code in certain conditions. Hope it helps. | I'm trying to wrap my head around rewriting some urls internally in Joomla! 1.7 with SEF features turned on but can't seem to figure it out:The following SEF URL exists (menu item):website.com/local/amsterdamWhat I would like is the following:http://website.com/local/amsterdam/trends(non-existant)
to renderhttp://website.com/local/amsterdam?show=trendswhile still displaying the first URL.Working with .htaccess the following works (but doesn't show SEF URL):RewriteRule ^local/amsterdam/trends$ index.php?option=com_content&view=article&id=14&Itemid=176&show=trends [L]But this doesn't:RewriteRule ^local/amsterdam/trends$ local/amsterdam?show=trends [L]I'm hoping to find a solution without having to use an id so that it will dynamically render the correct page for all cities. I'ld appreciate any thoughts on doing this in .htaccess as well as any different solutions to achieve this! Thanks in advance. | Rewrite custom urls with Joomla SEF |
I would suggest you to use something like:RewriteRule ^posts/(a-zA-Z0-9\-\.]+)/([0-9]+)/?$ view-post.php?title=$1&pid=$2 [NC,L,QSA]orRewriteRule ^posts/([a-zA-Z0-9\-\.]+)/?$ view-post.php?title=$1 [NC,L,QSA] | I need help with modifying the url of a website I am working on.The url is:domainname.com/view-post.php?title=post-title&pid=2I can only get it to saydomainname.com/2.htmlbut need it to saydomainname.com/posts/post-titleAny help will be greatly appreciated. | changing the url with modifying the .htaccess file |
You could add a new mime type with htaccess and set custom expire headers.Example using .xjs<IfModule mod_mime.c>
AddType application/x-javascript .xjs
</IfModule>
<IfModule mod_gzip.c>
mod_gzip_item_include file \.xjs$
</IfModule>
<FilesMatch ".(xjs)$">
Header set Cache-Control "max-age=43200"
</FilesMatch>or just use regex inFilesMatchto match your js file<FilesMatch "--[a-z0-9]+\.js$">
Header set Cache-Control "max-age=43200"
</FilesMatch> | Instead of generating links tofile.js, I'm calculating a version number or hash sum and linking tofile--bbe02f946d.js. I'm using the following redirect rule to then serve the current version of the file:RewriteRule ^(.*)--[a-z0-9]+\.js$ $1.jsNow, I want to set extremely far awayExpiresheaders for those requests:ExpiresActive on
ExpiresByType application/javascript "access plus 1 year"This works fine, but applies to not yet versioned resources (/file.jsrequests) too. How can I set the expires headers only for the requests matching the RewriteRule? Normally, I'd use<LocationMatch>, but that's not available since the application must be able to run on arbitrary servers where I can just modify htaccess. | Enabling mod_expire depending on request |
I think AuthMySQL does not allow anything without password authentication.Horewer, you can achieve what you want by doing it in horribly wrong way.You could write cron script which:loads allowed IP list from databasegenerates .htaccess file based on these IPsreplaces old .htacess with new one | I know that with.htaccessyou can add access users by usin MySQL database to try and authenticate users.https://helpdesk.islandnet.com/help/htaccess.php#mysqlBut I want to add that.htaccesslooks at the MySQL database and only allows IP addresses which are stored in that database.It is impossible? If not, how? | .htaccess allow IP from MySQL DB |
Ok after some further reading on the net and thanks to Salman's reply, I figured out the answer to my problem :)the code below will rewrite the dirty url to clean one...RewriteCond %{THE_REQUEST} ^.\?myparam=([a-zA-Z]+).RewriteRule ^(.*)$ /%1? [R=301,L]note that the question mark behind '/%1' is very very important because putting it there (on the redirect target) will clear the query string.after that, the code below will redirect the clean url to the dirty one without changing the url(still remain clean)RewriteRule ^([a-zA-Z]+)$ /index.php?myparam=$1 [L]this won't cause an infinite loop due to the usage of THE_REQUEST which will only respond to your request and not server side redirect (i think)you may need to read on mod_rewrite syntax guides to customize it for your own needs.. | Assuming my site will do something if the URL looks like thismysite.com/index.php?myparam=testIn .htaccess, I added the following line:#RewriteRule ^([a-z]+)$ /index.php?myparam=$1 [L]Which works great! URL mysite.com/test will redirect accordingly and everything worksI would like to get rid of the dirty URL so that if someone keys in manually mysite.com/index.php?myparam=test he will be redirected to mysite.com/test and still works, without going into an infinite loop.. | How to make sure only clean URL is used all the time? |
I would use 2 stylesheets to theme the page, and detect the browser and serve up the right css depending on what the browser is detected as. Have a look at the 'get_browser' function of PHPhttp://php.net/manual/en/function.get-browser.phpthen just have an if statement:if (preg_match('/mobile/i', $u_agent)) {
$css = 'mobile.css';
}and then just load the $cssHope that makes some sense. | I found some plugins like WP Mobile Pack, but I want to put together my own very simple theme switcher. (Just don't want any bloat.)I have a regular WordPress theme and I also created a WordPress Mobile theme as well. These are both standard WP themes that can be activated in the dashboard.How can I direct certain user agents directly to the mobile theme? (I don't want a mobile domain, sub-domain, or trailing directory.) www.example.com should be the domain for any visitor.The one catch is, I also want to offer a link to let users switch back. For instance, iOS devices should go to the Mobile Theme. But if they are on the large iPad, they may want to simply use the regular site. Having some sort of cookie override the default .htaccess or PHP redirection would be useful.Any help, specifically targeted at WP and handling WP theme switching would be truly appreciated. | WordPress Mobile Theme Switcher Without Plugin (User Agent and Cookie) |
Looks like the solution was to set RailsBaseURI to the path relative from the DocumentRoot on the server, not the REQUEST_URI!I had thought it referred to the actual URI string, but it turns out that is not the case! | I'm trying to install Redmine, and I am having trouble making Phusion Passenger work with any directories other than the DocumentRoot.I've put the public directory downloaded from Redmine into ~/www/public/entry/redmine.mysite.com/, and the rest of the directories in ~/www/app/redmine.mysite.com/.I've added the following line to the .htaccess file inside the public folder:PassengerAppRoot ~/www/app/redmine.mysite.comWhenever I try to load up the page, it just gives me the plain Mozilla file not found page.Any thoughts?Additional Info:I have a codebase set up so that apache resolves any given request URI to a particular entry folder, as follows:DocumentRoot is ~/www/publicIn this folder is a .htaccess file, including the following rule:RewriteCond ${lowercase:%{SERVER_NAME}} ^(dev\.)?(stg\.)?(www\.)?(.*)$
RewriteCond %{REQUEST_URI} !^/resource/(.*)$
RewriteRule !^entry/ entry/%4%{REQUEST_URI}If I create a new VirtualHost for port 3000, with DocumentRoot=~/www/public/entry/redmine.mysite.com/, everything loads up correctly.However, if instead I use my codebase's mod_rewrite-based resolution, I get a page not found error.If I visit redmine.mysite.com/404.html, it loads the 404.html page that is in the correct folder.If I change the PassengerAppRoot to ~/www/app/redmine.mysite.com/test, it informs me that the directory does not appear to be a valid Ruby on Rails application root. | Phusion Passenger Configuration via .htaccess |
-1Your RewriteCond:RewriteCond %{REQUEST_URI} !pagespeedhas two problems with it.First, QUERY_STRING is a separate variable from REQUEST_URI, and so your REQUEST_URI doesn't in fact contain pagespeed.Second, it's case sensitive.So I believe what you meant wasRewriteCond %{QUERY_STRING} PagespeedNote if you're unsure of the case of the string, or if it could be either, you can use the [NC] flag on the end of RewriteCond to indicate that it's case insensitive. | I have a small problem with themod_pagespeedmodule in Wordpress on Apache server. I'm getting a 404 related only toPNGimages, but not always, not for all and not even for the same images. Automatically, sometimes you see, sometimes not instead.When it happens, i try to disable the mod_pagespeed inserting?ModPagespeed=off, and magically PNG images appear correctly.Always when it happens, hanging on the URL?ModPagespeed=on&ModPagespeedFilters=you see the PNG images.Again you see the PNG also enabling a filter at a time with for example:?ModPagespeed=on&ModPagespeedFilters=extend_cache.At this point, i think that it might be a problem ofRewriteCondin.htaccessfile. So, i put the exception:RewriteCond %{REQUEST_URI} !pagespeedunder:RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-dBut still doesn't work. Do i also hang it with the basic rules of Wordpress? That are the follow:RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]What do you think?Thanks in advance | Why i'm getting a 404 for PNG in mod_pagespeed |
-1Try disabling theMultiViewsoption as per@ValdimirDimitrov's comment. | RewriteRule ^profile?$ profile.php [NC,L]
RewriteRule ^profile/?$ profile.php [NC,L]
RewriteRule ^profile/([0-9]+)/?$ profile.php?profile_id=$1 [NC,L] # Handle product requests
RewriteRule ^profile/([0-9]+)/([a-z0-9A-Z]+)/?$ profile.php?profile_id=$1&p=$2 [NC,L] # Handle product requests
RewriteRule ^profile/([0-9]+)/([a-z0-9A-Z]+)/([a-z0-9A-Z]+)/?$ profile.php?profile_id=$1&p=$2&id=$3 [NC,L] # Handle product requests
RewriteRule ^([a-z]+)/?$ index.php?p=$1 [NC,L] # Handle product requestsWhen I open{url}/profile/{profile_id}the request is going to profile.php but profile_id is not accessible via $_REQUEST['profile_id'].
All other requests are working properly.Can anyone help what can be the possible reason? | .htaccess not working properly on ubuntu server |
-1If you use Mamp, you have to configure the htaccess file
and modify htaccess in folder root / app/webroot and app/config<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase / "production" or /nameFolder/ "dev"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L] | I have a CakePHP 2.x app here:/Users/cameron/Sites/ExampleApplicationAnd inside it has the standard structure:/app
/webroot
etc.However when I go to:localhost/~cameron/ExampleApplicationI get the error:The requested URL /Users/cameron/Sites/ExampleApplication/app/webroot/ was not found on this server.However if I setup a VirtualHost like:<Directory "/Users/cameron/Sites">
Header set Access-Control-Allow-Origin "*"
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "/Users/cameron/Sites/ExampleApplication"
ServerName example.com
UseCanonicalName Off
</VirtualHost>It works fine!Any ideas why it works for the VirtualHost but NOT when accessing it via the usual localhost?Here is what is inside the three .htaccess files:<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule> | CakePHP only works on Mac local when using VirtualHost |
-1What is the mistake here ?The mistake is that thereisno%{HTTPS_HOST}variable. The%{HTTP_HOST}is the request header (Host) that's part of the HTTP protocol. You don't need the 3rd line, what you want to do is check whether or not the request was HTTPS using the%{HTTPS}variable like you're doing in the first condition:RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://mydomain.com/$1 [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://mydomain.com/$1 [L,R=301] | This question already has answers here:Generic htaccess redirect www to non-www(25 answers)Closed10 years ago.I need to redirect one domainhttps://www.mydomain.com to https://mydomain.com.I use this .htaccess and it not work for me.Previously i have the ssl cert forhttps://www.mydomain.comand it was broke, we register the new ssl for the hosthttps://mydomain.comIn the WHM there is only one ssl host but in the cpanel there are two hosts one is oldwww.mydomain.comandmydomain.com(Is this effect on the redirection?)the .htaccess is below.RewriteEngine on
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]I am getting the security alert always while i typehttps://www.mydomain.com.What the mistake that i did here?Thanks in advance | Redirect all https://www.mydomain.com to https://mydomain.com using htaccess (2 SSL HOST in cpanel) [duplicate] |
If anyone needs help with this I was able to work with a friend of mine at Hostinger and here is what your .htaccess file will need to include.Copy and paste exactly:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule> | I need to rewrite or add to my existing .htaccess file so that my hosting service (Hostinger) can use a single index.html file for all pages instead of trying to fetch a new file server-side. I am using React with React-Router and it does not understand how to use the paths correctly.Existing File:This was used to fix an issue with my SSL========================== File ===========================RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.matthewendicott.space/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.matthewendicott.space/$1 [L,R=301]====================== Testing and Similar Issues ==============Here are a few things that I have tried:https://hostpapasupport.com/set-301-permanent-redirect-using-htaccess/https://mediatemple.net/community/products/grid/204643080/how-do-i-redirect-my-site-using-a-htaccess-fileAnd here is a similar issue:How to fix "404" error when directly accessing a component in react | .htaccess Rewrite for React using React Router |
Since you're in the context of WordPress, you can utilize its redirect functionality.Like this ( in functions.php ):function redirect_homepage() {
if( ! is_home() && ! is_front_page() )
return;
wp_redirect( 'http://redirect-here.com', 301 );
exit;
}
add_action( 'template_redirect', 'redirect_homepage' ); | I have a blog, lets sayexample.comand another blog installed inexample.com/npwhich is not multisite but a different WordPress installation.What I want is to redirectexample.comhomepage only toexample.com/np. It would be great if that redirection is a 301 moved permanently redirection.If I place the 301 redirection in WordPress header file,header.php, it will redirect every page. And if I check if the page is home and try a 301 redirection that's not possible because header redirection should be placed at top.How to achieve this? | Redirect only WordPress homepage with a 301 redirect |
Rather than specifying a Favicon in htaccess you would be better off using the following META tag within the HEAD area of every page:<link rel="shortcut icon" href="http://example.com/myicon.ico" />If this is not possible (perhaps you have a very large static website) you can simply store the file (name it favicon.ico) in your website's root folder (e.g. /public_html/) as browsers will automatically look there first. | I want to Set Favicon for All files in my site using htaccess ?? | How to set favicon default for all pages using htaccess |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.