Hi Stackoverflow community,
I've been reading through most of the other .htaccess questions, and tried different solutions on my .htaccess file but with no success.
Here's the thing: I have a website (based on CodeIgniter) that already has a good SEO positioning. Now, the customer wants it translated to another language, but I dont want to lose that SEO so I thought of redirecting a URL like http://www.domain.com/contactUs to http://www.domain.com/en/contactUs, being (en) the current positioned language. CI would handle the other language as usual without problem. Im currently doing tests on localhost, so the following rules will have only "domain" instead of "domain.com".
I've tried these Rewrite rules:
RewriteEngine on
Options +FollowSymlinks
RewriteCond ^(.*)/domain/(.*) !^/en/
RewriteRule ^(.*)/domain/(.*)$ $1/domain/en/$2
I want the RewriteCond to filter URLs coming in the new language so that the RewriteRule is not executed. What am I doing wrong?
Do this:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/en/ [NC]
RewriteRule ^(.*)$ /en/$1 [L]
You should put all your text in unique language files, then load them like so:
$this->config->set_item('language',"your_language");
$this->lang->load('default', "your_language");
To write out the content, the use:
$this->lang->line('message_id');
More info:
http://codeigniter.com/user_guide/libraries/language.html
This should more efficient than creating a duplicate site while still being SEO friendly. In fact, it should be more SEO friendly.
RewriteCond $2 !^en/
RewriteRule ^(.*)/domain/(.*)$ $1/domain/en/$2
Related
I'm having a bit of a trouble finding the right way to this:
I'm about to launch a site, www.domain.com, but it's not quite yet ready for the public eyes just yet. So I want to redirect all visitors (except myself) to www.domain.com/teaser.html.
How can I do this, so I keep the site content hidden from visitors, without creating a loop if I redirect base url? How would a htaccess string look like?
If I create something like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^xxx.xxx.xxx.xxx
RewriteRule .* /coming-soon.html [R=302,L]
It just create a loop. How can I do this without creating a loop?
As mentioned in this question.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !=123.45.67.89
RewriteRule index.php$ /teaser.php [R=301,L]
I'm new to this modrewrite beast. I managed to get it working and I can normaly load index.php as index.html for example.
Problem is when I try to navigate to index2.html and I get error 404 error, The requested URL /index2.php was not found on this server.
I have this code in my .htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]
I've tryed few things, but I just get caught in the loop.
Basicaly I want rewriting from PHP to HTML, but I want to see the files which are actually HTML work aswell.
My 2nd question, perhaps most important is, how good is that in SEO terms, is it just as normal or are there any downsides of using such rewrite rules?
Try adding a condition for -f
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*)\.html$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)\.html$ $1.php [nc]
This checks to make sure the the file exists as a php before rewriting
As for your second question, it doesn't make a big difference either way, whether extensions are html or php. Its mainly so it appears you're serving static content.
Im developing a website which supports SEF urls. I use PHP as serverside language. I know htaccess basic codes how works with it. But the problem is if I want to rewrite a php get link I have to put each both links on htaccess like this.
RewriteRule ^sign-in$ index.php?view=signin
RewriteRule ^register$ index.php?view=register
RewriteRule ^jobs$ index.php?id=2
Is there any possible way to automate urls with htaccess and url particular alias instead of adding Rewrite rules manually? something like joomla? I was trying to understand how joomla htaccess connects with particual alias. But I still couldn't understand how it works. I cant uderstand how joomla htaccess makes relationship with article aliases. Please help. Thanks in advance.
If there isn't any difference for how an id looks like compared to how a view looks like (in your example, register is a view and jobs is an id=2), then you have to do one or the other individually:
To "automate" the views you could try just doing this:
RewriteEngine On
# all id's here:
RewriteRule ^jobs$ index.php?id=2 [L]
RewriteRule ^something-else$ index.php?id=3 [L]
RewriteRule ^another$ index.php?id=4 [L]
# this will do all views
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?view=$1 [L]
EDIT: If you need to do these mappings via an external set of aliases, you need to take a look at the RewriteMap directive. You will need to have access to the server or vhost configs in order to setup the map, but your rules can stay in an htaccess file.
Say you have a text file called "joomla_maps.txt" that looks like:
jobs id=2
another id=3
sign-in view=sign-in
register view=register
etc...
You can use that mapping by setting it up in a RewriteMap (in vhost/server config)
RewriteMap joomla txt:/path/to/joomla_maps.txt
And later in your htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?${joomla:$1} [L]
Take a look through the RewriteMap docs to get some examples of other kinds of maps, including executing a script or using a dbm hash map.
I know questions similar to this are common. I just don't even know where to begin with rewrite rules with the /'s and .'s I don't know how to retrofit other peoples solutions to mine. Onto my situation:
I am using a basic get on the index.php file that looks like
http://www.example.com/index.php?page=about
I want to rewrite that to
http://www.example.com/about
I know this is fairly simple rewrite wise, but its just a totally different language which I have tried and failed to comprehend. Thanks
Try this:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
Or even:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(?!index.php\b).* index.php?page=$0 [L,QSA]
Note:
You should always set the RewriteBase in an .htaccess file.
I've generalised this so that index.php picks up any string which isn't mapping to a real file
The (?!index.php\b) is a regexp which says "but don't match to index.php"
You will need the [QSA] flag if your requests can contain request parameters. This merges them.
How can I create a PHP page system that we access without .php extension and without ?page= variable?
There's a simple exemple:
http://www.exemple.com/portfolio/1
Instead of:
http://www.exemple.com/portfolio.php?id=1
It would be great for me because I'm a web designer and this is a thing I never did. So it would be good to know this! Also I will use this in my website.
you would need the following in your .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}%1.php -f
RewriteRule .+ %1.php [QSA,L]
You're looking for mod_rewrite.
RewriteEngine On
RewriteRule ^/profile$ /account.php?profile [L]
Create .htaccess file in your web root and enter following.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^account/([0-9]+)$ account.php?id=$1
OR
See mod_rewrite, in case URL rewriting, if you trying to do such.
You can use multiviews, or better and more used: mod_rewrite module from apache. It can be via a .htaccess file where you create rewrite rules like
RewriteEngine On
RewriteRule ^(.*)?(.*)$ /$1.php?Action=$2 [L]