Pagination and mod rewrite - 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

Related

how to redirect laravel website using .htaccess or bootstrap file change

how to redirect laravel website using .htaccess or bootstrap file change
I have a domain www.mydm.com/folder/public but maximum url says my.mydm.com how can i tell my domain my.mydm.com to hit is equal to www.mydm.com/folder/public laravel
Wrote this
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RewriteRule /assets www.mydm.com/folder/public [R=301,L]
does not help me
Any idea please guide thanks in advance
Please guide
Can you try with this
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteEngine On
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
step 1:
Rename File server.php INTO index.php
step 2:
Update .htaccess
Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

Blank page laravel

Larave displays a white page, storage is 777, bootstrap is 777, I have .env working, I did a composer update, my htacess
It does not show any error in php.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]
Do you try use the default Laravel htaccess ?
Try use this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Rewrite ignoring files in a directory when it exists

I have been using successfully the following rewrite that takes www.site.com/123/abc to points it to www.site.com/index.php?id=123&page=abc
RewriteEngine On
RewriteRule ^([0-9]+)$ http://%{HTTP_HOST}/$1/ [R,L]
RewriteRule ^([0-9]+)/(.*)$ /index.php?id=$1&page=$2 [L]
Until now. When a directory that exists and matches the $1 www.site.com/123/ the files in the /123/ directory I no have access to. If I try changing the rewrite to the following everything stills works except the files.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ http://%{HTTP_HOST}/$1/ [R,L]
RewriteRule ^([0-9]+)/(.*)$ /index.php?id=$1&page=$2 [L]
What would one use to keep using mod rewrite and not ignore files in a directory when it exists.
RewriteConds only apply to the very next RewriteRule. Since you have two rules you need to repeat your conditions.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ http://%{HTTP_HOST}/$1/ [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/(.*)$ /index.php?id=$1&page=$2 [L]
Or you could filter out files and directories at the top before continuing with your rewrite rules:
# Do nothing if URL points to existing file or directory.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.*) $1 [L]
RewriteRule ^([0-9]+)$ http://%{HTTP_HOST}/$1/ [R,L]
RewriteRule ^([0-9]+)/(.*)$ /index.php?id=$1&page=$2 [L]

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.

MOD_rewrite from static to dynamic URL

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]

Resources