Menu
  • HOME
  • TAGS

.htacces rewrite by cookie value

Tag: apache,.htaccess,mod-rewrite,cookies,url-rewriting

I have a website in 2 languages. I'm inserting the text for each language through php constants and I define the user language through a cookie (lang=es or lang=en).
Now the base url in each language is www.webname.com/ but i want to rewrite it depending on the language. If the cookie is set to es the url must be www.webname.com/es/ and if it's in en must be www.webname.com/en/.
I'm looking in some manuals and tutorials but i'm really very bad with regular expressions.

EDIT: I'm working on something like that in my .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_COOKIE} lang=en;? [NC]

If I put a redirection like:
RewriteRule ^ http://www.google.com [NC,L]
after it, it works but i don't know how to do the same with a rewrite.

Best How To :

Try this :

 RewriteEngine On 
 #Redirecting with the cookie value
 RewriteCond %{HTTP_COOKIE} ^lang=(en|es)$ [NC] 
 RewriteRule ^(.*)$ http://example.com/%1/$1 [R,L] 

If the cookie is set to "en" this will redirect every requests to example.com/en/

Pretty URLs aren't working after upgrade to Mediawiki 1.24.2

.htaccess,ubuntu,mediawiki

Make sure, that you checked the following points: - the mod_rewrite module is enabled - you allow the htaccess to overwrite the settings you want (check, if the AllowOverwride directive is set, e.g. (that would be the easiest value) to all, see http://httpd.apache.org/docs/current/de/mod/core.html#allowoverride # your directory definition AllowOverwride All #...

Page doesn't load after .htaccess redirect with parameters

php,.htaccess,url-rewriting

The order of your directives is incorrect. Use it as below instead: Options +FollowSymlinks Options -Indexes ErrorDocument 404 /404.php RewriteEngine On RewriteBase / # Add "www." RewriteCond %{HTTP_HOST} ^example.com$ RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] # Rewrite profile/x/x/x to profile.php RewriteRule ^profile/([^/]*)/([^/]*)/([^/]*)/?$ profile.php?url=$1&id=$2&ref=$3 [L] ...

Redirection loop (URL rewriting)

regex,apache,.htaccess,mod-rewrite,rewriting

I suggest not using .php in pretty URL, make it extension-less. Try these rules in v2/.htaccess: RewriteEngine On RewriteBase /v2/ RewriteCond %{THE_REQUEST} /message\.php\?ID2=([^&\s]+) [NC] RewriteRule ^ message-%1? [NE,R=302,L] RewriteRule ^message-(.+)/?$ message.php?ID2=$1 [L,QSA,NC] ...

Htaccess rewrite URL with virtual directory and 2 variables

regex,apache,.htaccess,url,rewriting

ok , I assume you want to change the URI from http://www.example.com/result.php?team=arsenal&player=ospina to http://www.example/subdirectory/arsenal/ospina.html so this is the .htaccess that will do that for you RewriteEngine on RewriteCond %{QUERY_STRING} ^team=(.*)\&player=(.*)$ RewriteRule ^(.*)$ http://www.example.com/subdirectory/%1/%2.html [R=301] you can test it with htaccess tester here http://htaccess.madewithlove.be/ and some useful links for documentation and...

ssl certificate with and without www

apache,ssl

Usually, registries create certificates for your hostname and the domain above (see https://en.wikipedia.org/wiki/SubjectAltName). If the registry does not support this, than choose a different one.

deploy django under apache mod_wsgi waiting for localhost

python,django,apache,mod-wsgi

Try adding to the Apache configuration file: WSGIApplicationGroup %{GLOBAL} See: http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API As the log snippet shows the WSGI file at least being loaded, which would only happen if a request is received, the issue may that you are using third party extension modules for Python that will not work in...

Apache httpd connection refused during stress test using jmeter

apache,jmeter,connection-refused

It's not a jmeter issue: check components between jmeter and apache (firewall, load balancer, ddos protection ...) check apache settings, to check this rampup slowly and see starting from which load you get those errors. ...

after using mod_rewrite link are not found

php,.htaccess,mod-rewrite

So you want the assets to be requested correctly? I guess you're using incorrect relative paths for linking those in your page's code (something like "images/image.jpg"..). If that's the folder structure you have, try to go one level up and use this path: <img src="../admin/images/image.jpg" ... or, in the case...

mod-rewrite to remove a folder

apache,.htaccess,mod-rewrite

Your rule is backwards - it works the other way around. You can try with the following: RewriteRule ^folder1/folder2/(.*)$ /demo/folder1/$1 [R,L] Or perhaps you'd like to make folder1 dynamic: RewriteRule ^([^/]+)/folder2/(.*)$ /demo/$1/$2 [R,L] If one of these works for you, and you would like to make the redirect permanent, you...

htaccess errors after upgrading Apache from 2.2 to 2.4

apache,.htaccess

The NoCase ([NC]) doesn't even make sense there as you're not matching anything. Just take it out. RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1\.php -f RewriteRule ^(.+?)/?$ /$1.php [L] ...

Apache - finding configuration file path

windows,apache,server

you can use httpd.exe -S it will list the config files used by all VHOSTs

Unable to increase PHP Memory Limit

php,apache,memory,memory-management,out-of-memory

So it turns out the memory limit was being increased properly, just not being reflected in phpinfo(). The reason it was not reflecting in the phpinfo() echo, is because I was making the memory increase in the controller, and then echoing phpinfo() from the view, so the increase was not...

Apache Regex How To Get This Value

php,regex,apache,.htaccess

The query string is separate from the request uri. In your case you only want to add a value to it, so you can use the [QSA] (Query String Append) flag to pass the entire query string with the value you captured from the URI Try: RewriteRule ^demo/(.*)$ demo.php?utm_campaign=$1 [L,NC,QSA]...

What are correct permissions for Linux Apache2 PHP 5.3 log file?

php,linux,apache,logging,permissions

I'd simply set its owner to apache user. This will give you the name of apache user : ps aux | grep httpd In my case (CentOS), it's 'apache' but sometimes it's 'www-data'... chown apache:apache /var/log/httpd/php_errors.log chmod 600 /var/log/httpd/php_errors.log ...

Make dynamic links (with ?) return error 404 not found

apache,.htaccess,dynamic,hyperlink,http-status-code-404

I assume you're asking for any request containing a query string to return a 404. If that is what you want, use the below: RewriteEngine On RewriteCond %{QUERY_STRING} .+ RewriteRule .* - [R=404,L] This will use the regex .+ to check if there are one or more characters in the...

Remove plus sign from url using .htaccess

php,regex,apache,.htaccess,mod-rewrite

You can add a new rule for +/- conversion: Options -MultiViews RewriteEngine On RewriteBase /indianrealitybytes/ RewriteCond %{THE_REQUEST} /search_advance\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^([^+]*)\+(.*)$ $1-$2 [R=302,NE,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_advance.php?keywords=$1&f=$2 [QSA,L,NC] ...

Exporting Data from Cassandra to CSV file

apache,csv,cassandra,export,export-to-csv

The syntax of your original COPY command is also fine. The problem is with your column named timestamp, which is a data type and is a reserved word in this context. For this reason you need to escape your column name as follows: COPY product (uid, productcount, term, "timestamp") TO...

Virtual host returns the default host on another pc

apache

I think the /etc/hosts file configuration for the PC-A is not correct. ::1 ip6-localhost ip6-loopback www.test.tld The above mentioned entry seems to be problematic. Instead of that please point the IPv6 address of PC-A to www.test.tld and remove the entry for the www.test.tld from the loopback address....

Pattern matching in htaccess rewrite condition

apache,.htaccess,mod-rewrite,https

You need to tell the RewriteCond what to match !/go/ against. Change the second line to: RewriteCond %{REQUEST_URI} !/go/ [NC] ...

How to create a private certificate for connecting to a website

apache,ssl,privatekey,digital-certificate,self-signed

It sounds like you want to use client-side SSL certificates for authentication. The Apache documentation covers this use case in some detail (that's for version 2.4; see here for version 2.2).

Rewrite url not working in htaccess

php,apache,.htaccess,mod-rewrite,url-rewriting

QUERY_STRING is only used to match query string without URI. You need to use: Options -MultiViews RewriteEngine On RewriteBase /mywbsite/ RewriteCond %{THE_REQUEST} /search_data\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_data.php?keywords=$1&f=$2 [QSA,L,NC] ...

How to rewrite example.com/catelogue.php?page=3&cat1=fruit&cat2=apple with .htaccess

php,apache,.htaccess,mod-rewrite,url-rewriting

This should work. Try your rules this way. It works for me. Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^catelogue/([^/]+)/([^/]+)$ catelogue.php?page=3&cat1=$1&cat2=$2 [NC,L] RewriteRule ^catelogue/?$ catelogue.php?page=3 [NC,L] RewriteRule ^home/?$ index.php?page=1 [NC,L] ...

Redirect specific Url variables

php,.htaccess,mod-rewrite,redirect

Try this : RewriteEngine On RewriteCond %{QUERY_STRING} ^s=([^&]+)&type=([^&]+) [NC] RewriteRule ^data.php$ /d.php?s=%1&t=%2 [NC,R,L] This will externally redirect a request for : /data.php?s=foo&type=bar to /d.php?s=foo&t=bar ...

How to set default virtual server (sites-available) in Apache?

apache

Listen 80 Listen 8080 NameVirtualHost 172.0.0.1:80 NameVirtualHost 172.0.0.1:8080 <VirtualHost 172.0.0.1:80> ServerName www.ourdomain.com DocumentRoot /www/ourdomain </VirtualHost> <VirtualHost 172.0.0.1:8080> ServerName www.mydomain.com DocumentRoot /www/mydomain </VirtualHost> replace 172.0.0.1 with your IP I hope this will help you....

Force WWW when URL contains path using .htaccess

.htaccess,session,url,redirect

It seems to look ok but one thing you should do is always put your other rules before the wordpress rules as a habit. When using wordpress it should generally be the last set of rules since it does all the routing. Now for the redirect, you should probably use...

How to write .htaccess file for AJAX page

php,jquery,ajax,.htaccess

I think it's more related to apache than ajax. Anyway - your RewriteRule is ^findcontents/([A-Za-z0-9-]+)/?$ and you post to the url '/findcontents'. Did you try to post to '/findcontents/asdf' ? Another option is to add ^findcontents$ to your rules. If none of these works for you please provide some more...

Excluding certain pages from being redirected to https

wordpress,.htaccess,redirect,https,http-redirect

Try using THE_REQUEST instead of REQUEST_URI: <IfModule mod_rewrite.c> RewriteEngine On # Go to https if not on careers RewriteCond %{SERVER_PORT} =80 RewriteCond %{THE_REQUEST} !/careers/[\s?] [NC] RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L] # Go to http if you are on careers RewriteCond %{SERVER_PORT} !=80 RewriteCond %{THE_REQUEST} /careers/[\s?] [NC] RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R,L] </IfModule>...

Multiple subdomains to same address

apache,subdomain,vhosts

Yes, If you wish to use multiple addresses like subdomains to the same location you can do this. <VirtualHost *:81> ServerName example.com ServerAlias www.example.com sub1.example.com sub2.example.com DocumentRoot /var/www/example.com #more stuff etc here if needed </VirtualHost> It's part of name based virtual host. http://httpd.apache.org/docs/2.2/vhosts/name-based.html...

Unable to connect to your database server using the provided settings in Codeigniter

mysql,.htaccess,codeigniter

$db['default']['password'] = ''; there is an space, remove it use below settings $db['default']['hostname'] = 'localhost'; $db['default']['username'] = 'root'; $db['default']['password'] = ''; $db['default']['database'] = 'test_bs'; $db['default']['dbdriver'] = 'mysql'; $db['default']['dbprefix'] = ''; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ''; $db['default']['char_set'] = 'utf8'; $db['default']['dbcollat'] = 'utf8_general_ci';...

Best way to block countries [on hold]

php,apache,.htaccess

You don’t have to fill your .htaccess file with thousands of lines of IPs. Instead, you can install a C library and an Apache module to do the heavy lifting for you. MaxMind provides a popular free database that is often used for IP lookups. Their GeoLite2 is a free...

Django file upload took forever with Phusion Passenger

django,apache,file-upload,passenger

Passenger author here. Try setting passenger_log_level to a higher value, which may give you insights on why this is happening. I don't know which Passenger version you are using, but in version 5, the Passenger request processing cycle looks like this: Apache receives the request. Once headers are complete, it...

Rewrite non-dynamic pages using htaccess

apache,.htaccess,mod-rewrite

Try the following rules in your /htaccess file : RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^.-]+)\.php [NC] RewriteRule ^ %1/ [NC,R,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^-]+)-([^.]+)\.php [NC] RewriteRule ^ %1/%2/ [NC,R,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ $1.php [QSA,NC,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/?$ $1-$2.php [QSA,NC,L] ...

How to enable mod_rewrite on Apache 2.4?

php,wordpress,apache,mod-rewrite,centos7

i found the way to know if a module is loaded or not, here's to command to list the modules enabled: apachectl -M | sort It will list all enabled modules alphabetically. Wordpress has an .htaccess but default where it enables Rewrite_Mod for its use: # BEGIN WordPress <IfModule mod_rewrite.c>...

What exactly IS Kafka Rebalancing?

apache,apache-kafka,kafka-consumer-api,kafka

When a new consumer joins a consumer group the set of consumers attempt to "rebalance" the load to assign partitions to each consumer. If the set of consumers changes while this assignment is taking place the rebalance will fail and retry. This setting controls the maximum number of attempts before...

Codeigniter URL routing issues in .htaccess

php,apache,.htaccess,codeigniter-2

Okay, as stated before I am not a CodeIgniter guru. What I do know is that the following works for me: Config: $config['base_url'] = "http://www.deltadigital.ca/"; # or use $config['base_url'] = ""; $config['uri_protocol'] = "REQUEST_URI"; $config['index_page'] = ''; Routes: $route['default_controller'] = "tlc/view"; $route['(:any)'] = "tlc/view/$1"; $route['404_override'] = ""; Controller: <?php if...

PHP script doesn't execute on Apache server

php,apache

I'd look for errors in the console for the JavaScript. If there are none I would try to run the PHP by itself. Add error reporting to the top of your PHP file(s) right after your opening If that doesn't reveal anything add some XML error handling as outlined here...

mod_rewrite - force redirecting to rewritten URL

apache,.htaccess,mod-rewrite,redirect

You need a new rule for that redirect: Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} /(?:index\.php)?\?search=([^\s&]+) [NC] RewriteRule ^ search/%1? [R=302,L,NE] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^search/(.*)$ /?search=$1 [L,QSA] ...