MOD_rewrite from static to dynamic URL - mod-rewrite

I have the following URL which is correct...
http://www.mydomain.co.uk/cask-beer/wells-and-youngs
but i need it to render this page:
http://www.mydomain.co.uk/cask-beer?catID=4
This is my current .htaccess which serves other pages correctly already. I want to add something to manage this other rule. I had an attempt where you can cask-beer
php_flag magic_quotes_gpc off
AddDefaultCharset UTF-8
Options -Indexes +FollowSymLinks
#
# Setting rewrite rules
#
<IfModule mod_rewrite.c>
RewriteEngine On
# Set next line to your Wolf CMS root - if not in subdir, then just /
RewriteBase /
# Rules to allow install sequence to test for mod_rewrite support
RewriteRule ^install/index.html$ install/index.php?rewrite=1 [L,QSA]
RewriteRule ^install/index.php$ install/index.php?rewrite=1 [L,QSA]
RewriteRule ^install/$ install/index.php?rewrite=1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# Administration URL rewriting.
RewriteRule ^admin(.*)$ admin/index.php?$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
# Main URL rewriting.
RewriteRule ^(.*)$ index.php?WOLFPAGE=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?cask-beer?$1
</IfModule>
Any help would be appreciated.
Cheers

Just add this rule at the top of your other rules:
RewriteRule ^cask-beer/wells-and-youngs$ cask-beer?catID=4 [L,QSA]

Related

Apache2 mod_rewrite - how to add trailing slash to only one subdirectory

I'm using Apache 2.2 with two servers:
Development: localhost/project/public
Production: www.example.com
I have an existing rewrite rule for clean urls (to remove 'index.php' from the url).
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have one special route that only works if a trailing slash is present:
special route (development): localhost/public/documentation/
special route (production): www.example.com/documentation/
How do I add a rewrite rule to my existing .htaccess to always add a trailing slash, but only for the documentation route?
You just need to add another RewriteRule that matches only against /documentation i.e. without a trailing slash. The first rule adds the trailing slash and then your existing rule adds the index.php.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(documentation)$ $1/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If you would like the browser's address bar to also reflect the trailing slash change the rule to
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(documentation)$ $1/ [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Don't forget to add these directives first once per .htaccess file:
Options +FollowSymlinks
RewriteEngine on
And then you can try this:
RewriteRule ^/?(documentation)$ /$1/ [R,NC,L]
Or this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} (.+)/([^/]+)$
RewriteRule ^/?(documentation)/(.+)$ /$1/$2/ [R,NC,L]
I'm confused about your question..

Codeigniter No input file specified

I know that this question has been asked maybe thousands of time before, I looked at most of them and could not fix for my case :s
I have a codeigniter framework installed on godaddy hosting company and i read that i have to create a .htacces file and put this code into:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
But this does not fix for my case, is it that I have this site hosted under another domain?
for ex the structure of my ftp looks like below:
/
facelajm
studenti
fxclod
and I am trying to get the site following url www.facelajm.com/studenti which opens the main page fine, but when i try to login or reg it just returns me No input file specified.
Anyone could help me?
Seems that in certain configurations the CI core misses the rules, the .htaccess I'm using now:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
ErrorDocument 404 index.php
In my case (dev: a subfolder, prod: an "addon domain") the magic was provided by those two extra lines:
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
Source:
http://www.diegodicamillo.com.ar/blog/2012/09/19/no-input-file-specified-codeigniter-error-problema-resuelto/
From your question what i understand is you are running the codeignitor in a subfolder("studenti") of the domain("www.facelajm.com"). So the below .htaccess code will work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
And also don't forgot to change the baseurl in configuration file(application/config/config.php) like below.
$config['base_url'] = "http://www.facelajm.com/studenti"
The above .htaccess which you used in your question will work for a sub domain.
So you can also create a sub domain and map the folder to the sub domain and use the code which you used in your question(For Reference i added below).
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
And also don't forgot to change the baseurl in configuration file(application/config/config.php) to the new subdomain(assuming new sub domain as http://codeignitor.facelajm.com/) like below.
$config['base_url'] = "http://codeignitor.facelajm.com/"
Here is the .htaccess file i have on a godaddy and it works fine:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Your problem might be the RewriteBase line if codeigniter is not in the root.
Please try this code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.)$ /index.php [L] or RewriteRule ^(.)$ index.php?/$1 [QSA,L]

How to rewrite url to omit one parameter

I have the following url. I want to rewrite the following url to omit the "view" from the url.
Here is currently my existing mod rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
http://example.com/page/view/helloworld
How do i rewrite the url to make it
http://example.com/page/helloworld
the keyword helloworld is dynamic.
Expert advice appreciated.
You might want to add the R=301 into the flags if you are worried about transfering SEO.
RewriteEngine On
RewriteRule ^(.+)/view/(.+)$ /$1/$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

Pagination and mod rewrite

The modrewrite below works when i have this which is exactly how i want: "www.mysite.com/files/person/john.html"
files.php?q=person
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*) /$1.php?q=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1 [L]
AddHandler application/x-httpd-php5 .html .htm .txt .php
The problem I have is when i have pagination and i have more than one person to display like this: "www.mysite.com/person/2" this becomes person.php, however there is no person.php and the modrewrite should only look at this condition below:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1 [L]
The thing is this "www.mysite.com/person/2" works when i only have this modrewrite:
Options +FollowSymLinks
RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)/(.*) /$1.php?q=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1 [L]
AddHandler application/x-httpd-php5 .html .htm .txt .php
however, the minute i uncomment it, it stops working? what to do, any ideas?
you can use regex for this.
DirectoryIndex index.php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([a-zA-Z]+)(.html)?$ /$1.php?q=$2 [L]
RewriteRule ^(.*)/([0-9]+)$ /files.php?q=$1&p=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1 [L]
</IfModule>
explanation for regex
() : means group and match that
[a-zA-Z] : means only letters lower or upper
.html : means match ".html"
? : means 0 or more times
[0-9] : means only numbers 0 to 9
+ : means at least 1 or more times

combining force-www with clean urls

I have this mod-rewrite in my htacces which enables some clean urls;
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
### LANGUAGE REDIRECT RULES start
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|nl)-?()?\/(.*\/?)$ index.php?language=$1&region=$2&symphony-page=$3&%{QUERY_STRING} [L]
### LANGUAGE REDIRECT RULES end
### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ ./index.php?symphony-page=$1&%{QUERY_STRING} [L]
</IfModule>
Now I would like to also force www, so I extended the code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteBase /
### LANGUAGE REDIRECT RULES start
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en|nl)-?()?\/(.*\/?)$ index.php?language=$1&region=$2&symphony-page=$3&%{QUERY_STRING} [L]
### LANGUAGE REDIRECT RULES end
### FRONTEND REWRITE - Will ignore files and folders
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ ./index.php?symphony-page=$1&%{QUERY_STRING} [L]
</IfModule>
However this results in none of my pages being found.
FYI A language redirect adds country-code parameters to the url on load.
How do I get these rules to play along?
You're probably missing the query string:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [QSA,L,R=301]
You can also use the QSA flag in your other rules, e.g.:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*\/?)$ ./index.php?symphony-page=$1 [L,QSA,B]
I also added B because you're using the backreference in a query string, so it needs to be escaped.
See the documentation.

Resources