I would like to have a RewriteRule match the "base" url/path of my site.
My base URL, once in prod, will be something like http://www.site.com, but is currently http://localhost/dev/site/ in dev. .htaccess file is in the "site" folder.
In the following examples, the first RewriteRule is the problem, and I can't get it to work. The 2nd and 3rd RewriteRules work fine. I need it to bring to index.php?l=default&rte=index if I reach the base path/URL.
Thanks.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/$ index.php?l=default&rte=index [NC,L]
RewriteRule ^([a-zA-Z]{2})/$ index.php?l=$1&rte=index [NC,L]
RewriteRule ^([a-zA-Z]{2})/([a-zA-Z-]+)$ index.php?l=$1&rte=$2 [NC,L,QSA]
Try these rules:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^/?$ index.php?l=default&rte=index [QSA,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([a-zA-Z]{2})/?$ index.php?l=$1&rte=index [QSA,L]
RewriteRule ^([a-zA-Z]{2})/([a-zA-Z-]+)/?$ index.php?l=$1&rte=$2 [QSA,L,QSA]
Related
I have following url i would like to hide id and make it clean url
https://www.evidhya.com/tutorials/tutorials.php?qid=569/AJAX/Introduction
clean url should be like below url
https://www.evidhya.com/tutorials/AJAX/Introduction
I'm able to achieve using below htaccess code.
https://www.evidhya.com/tutorials/569/AJAX/Introduction
but i don't want 569 id in url
RewriteEngine On
#RewriteBase /KSTA-Webinar/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#RewriteRule ^(\d+)/?$ tutorials.php?qid=$1/$2/$1/$3 [L,QSA]
RewriteRule ^([\w.-]+)/?$ get_data.php?qid=$1 [L,QSA]
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^title=([^/]+)/([^/]+)/([^/]+)/(.+)$
RewriteRule ^tutorials\.php$ /%1/%2/%4? [R=301]
RewriteRule ^tutorials/([\w+%]{2,50})$ /tutorials.php?qid=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ tutorials.php?qid=$1&user=$2&date=$3
RewriteRule ^([^/]+)/([^/]+)/(.+)$ tutorials.php?qid=$1/$2/$1/$3 [L]
Well, it seems the id is needed to determine the resulting url.
I would do this:
RewriteEngine on
RewriteRule (\d+)/(\w+)/(\w+) tutorials.php?qid=$1/$2/$3 [L]
and place this rule in tutorials/.htaccess.
And when someone goes to https://www.evidhya.com/tutorials/569/AJAX/Introduction it should load https://www.evidhya.com/tutorials/tutorials.php?qid=569/AJAX/Introduction
I have a htaccess file to match all of the occurrences. but it stops at second one. when i load /galeri/kategori/galeri-kategory-albumname/ it loads sayfa.php which has no relation with gallery page itself. It works fine on my localhost but trying to figure out why its not working in server.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)$ index.php?p=$1 [L]
RewriteRule ^(.*?)\/sayfa(.*?)$ index.php?p=$1&sayfa=$2 [L]
RewriteRule ^(.*?)\/kategori\/(.*?)\/$ index.php?p=$1&kategori=$2 [L]
RewriteRule ^(.*?)\/kategori\/(.*?)\/(.*?)\/$ index.php?p=$1&kategori=$2&sayfa=$3 [L}
Have it this way:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(.*)/kategori/(.*)/(.*)/?$ index.php?p=$1&kategori=$2&sayfa=$3 [L,QSA]
RewriteRule ^(.*)/kategori/(.*?)/?$ index.php?p=$1&kategori=$2 [L,QSA]
RewriteRule ^(.*)/sayfa(.*?)/?$ index.php?p=$1&sayfa=$2 [L,QSA]
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
I have an application which requires an htaccess file that contains the following:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(tileserver\.php)
RewriteRule ^(.*)$ tileserver.php?/$1 [L,QSA]
But I am getting 404 errors matching the following patterns:
http://107.170.120.88/tileserver/extra5/11/331/794.png
and:
http://107.170.120.88/tileserver/extra5/11/331/796.grid.json
It seems that any URL with the path:
tileserver/extra5/
needs to be instead:
tileserver/tileserver.php/extra5/
but I haven't had much luck writing an htaccess file to fix this.
If I take out the
RewriteCond $1 !^(tileserver\.php)
RewriteRule ^(.*)$ tileserver.php?/$1 [L,QSA]
the base script doesn't work, but then if I add something like:
RewriteRule ^tileserver/extra5/(.*)$ tileserver/tileserver.php/extra5/$1
it has no effect. How do I write this rule?
--- UPDATE ---
Here's the full htaccess:
DirectoryIndex tileserver.php
RewriteEngine on
RewriteBase /tileserver/
<FilesMatch "\.mbtiles$">
Order Allow,Deny
Deny from all
</FilesMatch>
RewriteRule ^(.+).jpeg$ $1.jpg [L]
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
RewriteRule ^tileserver.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ tileserver.php?/$1 [L,QSA]
Note that it is sitting in a subdirectory, in which the parent (root) has this htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Which removes index.php from all URLs (for codeigniter). Maybe that's conflicting?
With the datastructure like this:
example.com/tileserver/tileserver.php
and the url for the matching pattern
107.170.120.88/tileserver/extra5/11/331/794.png
which should result in 107.170.120.88/tileserver/tileserver.php?/extra5/11/331/794.png
your .htaccess should look something like this:
#turn on the rewrite engine
RewriteEngine On
#use the as base for your rewrite conditions the following folder
RewriteBase /tileserver
#since we don't want to rewrite the requests pointing directly to this script, leave it
RewriteRule ^tileserver.php - [L]
#if its not a file or a folder rewrite everything to tileserver.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#everything that comes after /tileserver is passed as argument to the php script
RewriteRule ^(.*)$ tileserver.php?/$1 [L,QSA]
I suspect the problem might be the [L] flag.
Instead, try:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(tileserver\.php)
RewriteRule ^(.*)$ tileserver.php?/$1 [QSA]
RewriteRule ^tileserver/extra5/(.*) tileserver/tileserver.php/extra5/$1 [L,QSA]
I have problem with my rewrite rule. I have new webpage in root/hrp. and if i open pages in that directory, then all is OK, but when i wanna surf those pages from root (without /hrp/) then is problem. I found some .htaccess rules and all working fine, but if i wanna execute some pdf,jpg,or php script directly, then come problem.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !hrp/
RewriteRule (.*) /hrp/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/hrp/index.php
RewriteRule ^(.*)$ /index.php [L]
if i put this bottom code on begining, i can open files directli, but pages don't work and vice versa
RewriteCond %{REQUEST_FILENAME} (/|\.php|\.html|\.htm|\.png|\.jpg|\.jpeg|\.gif|\.xml|\.rss|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule ^(.+)$ $1 [L]
Try adding this at the top instead:
RewriteRule \.(php|html?|png|jpe?g|gif|xml|rss|feed|pdf|raw)$ - [L,NC]
or you can try adding this condition to your hrp rule:
RewriteCond %{DOCUMENT_ROOT}/hrp/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/hrp/$1 -d
RewriteRule (.*) /hrp/$1 [L]
I have find solution
don't rewrite this files
RewriteCond %{REQUEST_URI} !.(gif|jpg|png|ico|css|js|swf|wav|mp3|less|cur|pdf|jpeg|txt|ico|zip|gz) [NC]
don't rewrite this folder - there i have php files, and dont rewrite this files
RewriteCond %{REQUEST_URI} !(folder1|folder2|file1.php|file2.php|file3.php) [NC]
all content is in "/hrp/" folder
RewriteCond %{REQUEST_URI} !hrp/
RewriteRule (.*) /hrp/$1 [L]
but url don't contains "/hrp/"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/hrp/index.php
RewriteRule (.*) /index.php [L]
I have a .htaccess file that has multiple rules to make the url's look "pretty".
This is the file:
RewriteEngine On
RewriteRule ^property/([^/]*)/?([^/]*)/?$ /property.php?ID=$1&Image=$2 [L]
RewriteRule ^property$ /property.php [L]
RewriteRule ^enquire/([^/]*)/?([^/]*)/?$ /enquire.php?ID=$1&Data=$2 [L]
RewriteRule ^enquire$ /enquire.php [L]
RewriteRule ^contact/?$ /contact.php [L]
RewriteRule ^home/?$ /index.php [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} ^/(property|property/.*|enquire|enquire/.*|contact|contact/.*|home|home/.*)$
RewriteRule ^([^/]*)$ /custompages.php?ID=$1 [L]
The first set of rules works for property, enquire, contact and home.
If the url is not one of these, e.g. www.foo.com/about-us, I want it to call the file custompages?ID=about-us but with this code, it isn't working. I am quite new to using .htaccess files and I can't figure out what the issue is myself.
Your last rule is not correct. Change that to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /custompages.php?ID=$1 [L]