I have two directory under my application directory
my_app:
.htaccess
lib:
entry.php
web:
css:
css_file1
css_file2
js:
js_file1
js_file2
My url will be like this http://example.com/my_app/my_path
Under the directory my_app, there are two directories web and lib.
If the my_path can be map to any file under the web directory, use it.
For example, http://example.com/my_app/css/css_file1 should map to my_app/web/css/css_file1.
Otherwise redirect it to lib/entry.php/my_path so that the the my_path can be accessed through $_SERVER['PATH_INFO'] The redirection should be internal. The redirection should not be visible to user.
I want to write configuration in .htaccess to accomplish it.
I wrote the code as given below.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*) ../web/$1
RewriteCond web/%{REQUEST_FILENAME} !-f
RewriteCond web/%{REQUEST_FILENAME} !-d
RewriteRule (.*) lib/entry.php/$1
</IfModule>
But I am getting 403 error.
I believe following should work for you in /var/www/.htaccess i.e. directly under $DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1/web/$2 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1/web/$2 -d
RewriteRule ^([^/]+)/(.*)$ $1/web/$1 [L]
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^([^/]+)/(.*)$ $1/lib/entry.php/$2 [L]
Related
I need to deny access for all excluded URLs:
mydomainname/filename.html
and redirect this request to:
mydomainname/index.php?page=filename.html
And the user should see in the address bar:
mydomainname/filename.html
And I want all styles and js scripts to work correctly.
How can I do this?
I am was trying this:
ErrorDocument 404 /
ErrorDocument 403 /
RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)(?=\.).html$ index.php?page=$1.html
#if the request is for existent dirs, forbid the request
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^ - [R=403,L]
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule !^index.php$ - [R,F,L]
Options All -Indexes
And I have server error 500.
Without "Options All -Indexes" js files can't be loaded and styles are not working.
So, my final .htaccess file:
RewriteEngine On
ErrorDocument 403 http://mydomainname
ErrorDocument 404 http://mydomainname
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
# Set the default handler.
DirectoryIndex index.php
# Internal redirect
RewriteRule ^(\w+)(?=\.).html$ index.php?page=$1.html
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ / [L,R]
This solution is not deny access to mydomainname/include/myfile.php (if this file is exist), but it cover all other issues.
Search for rewrite condition in .htaccess file. You will get an idea for it. Or add RewriteRule ^(.*).(gif|jpg|png|jpeg|css|js|swf)$ /public/$1.$2 [L,NC] this.
I have this site called precisely.me, and I have just bought a new hosting server for it.
In my .htaccess file, I want all my files within precisely.me/fpl/.php to also be accessible via precisely.me/fpl/. For eg -: precisely.me/fpl/epl-table.php should also be accessible via precisely.me/fpl/epl-table
Why is this not working?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I am using GoDaddy.com's hosting, and should admit that I have little knowledge about the .htaccess file
You may try this instead, in one .htaccess file in root directory.
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\.php [NC]
RewriteRule ^fpl/([^/]+)/? /fpl/$1.php [L,NC]
Maps silently:
http://precisely.me/fpl/filename
To:
http://precisely.me/fpl/filename.php
Where filename is a dynamic string.
For permanent redirection, replace [L,NC] with [R=301,L,NC].
I am aiming for clean URL's in my WP site, currently I have the following example:
Example:
PluginName: = gft_galleries
pageTitle: = gallery-one
http://domain.co.nz/pluginName/pageTitle/
Is there away within Wordpress or .htaccess to create the following but keep the correct structure underneath?
Example:
http://domain.co.nz/galleries/pageTitle
.htAccess
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)(.*)$ [NC]
RewriteRule ^(.*)$ http://%2/$1 [L,R=301]
RewriteRule ^gft_gallery/(.*)$ /gallery/$1 [L]
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
I think what you're looking for is this.
Add it to your .htaccess, if its wordpress though, your
rewrite engine will probably already be on, so omit that
line
#modified ;)
RewriteEngine On
RewriteRule ^gft_gallery/(.*)$ /gallery/$1 [L]
I guess another simple way to do this is with symlinks, by typing
$ ln -s gft_gallery/ gallery
into your terminal, or via a script
<?php symlink('gft_gallery','gallery'); ?>
remember if you use the PHP method above to add Options FollowSymLinks in
either your apache.conf or htacces
I have been working on my own mvc framework to further my web app learning, but am having trouble serving static resources. I am trying to have a single entry point into the application, aka a front controller, so in my project / I have an .htaccess file that redirects all requests to the app/ folder where another .htaccess passes the request uri to index.php (in app/) who delegates the request to the appropriate controllers.
However, when I try to serve up static content, such as javascripts or cascading style sheets, I still get redirected through app/index.php. I am also getting "favicon.ico does not exist in /var/www" errors in /var/log/apache2/errors.log (maybe because of symlink to ~/www?). I do not expect to because of the following .htaccess file in the root directory of my project root:
<IfModule mod_rewrite.c>
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
# ----------------------------------------------------------------------
# Suppress the "www." at the beginning of URLs
# ----------------------------------------------------------------------
# The same content should never be available under two different URLs - especially not with and
# without "www." at the beginning, since this can cause SEO problems (duplicate content).
# That's why you should choose one of the alternatives and redirect the other one.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
#----------------------------------------------------------------------
# Route static resources to respective files
#----------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond public/$0 -f
RewriteRule ^.+\.(jpg|gif|png|ico|css|js)$ /public/$0 [L]
#----------------------------------------------------------------------
# Redirect all other requests to the app folder
#----------------------------------------------------------------------
RewriteRule ^$ app/ [L]
RewriteRule (.*) app/$1 [L]
</IfModule>
and here is the .htaccess in my app/ folder:
<IfModule mod_rewrite.c>
RewriteEngine On
# ensure request is not path to filename or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# redirect all requests to index.php?url=PATHNAME
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Why can't I serve static content correctly? This would make sense to me if I wasn't trying to sent all static requests to public/, which is where my css, jpg, png, js, etc files reside. But I have a RewriteCond rule in there to send the requests for such files to the public dir... Confusing?
Assuming, from what I understood, that your project structure is the following:
/
/.htaccess
/app/.htaccess
/app/index.php
/public/static.js (for example)
Here is what I come up with, hoping it'll solve your problem:
the .htaccess in the root folder:
<IfModule mod_rewrite.c>
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteRule ^public/.+\.(jpg|gif|png|ico|css|js)$ - [L]
RewriteRule ^(.*)$ app/$1 [L]
</IfModule>
And the .htaccess in the app folder is unchanged.
Every request starting with public and being a file with the listed extensions won't be redirected which is done with the dash character.
The last rule allows to redirect a request to the app/index.php file.
I think the resulting behaviour is the expected one:
static files in the public directory are not redirected,
files with another extension in the public directory will be
redirected to app/index.php (maybe for some error treatment),
requests not starting with public will be redirected to
app/index.php.
i need to hide the extensions of my webpage and also want to let the user put the links in both (lower and upper) case:
Example:
the file name is demo.php
www.example.com/demo
www.example.com/DEMO
www.example.com/Demo
Running PHP in a LAMP server, no access to php.ini, just .htaccess
Actualy im using a file like this:
RewriteEngine On
RewriteBase /
RewriteRule ^/(OUTSOURCING|outsourcing|Outsourcing)$ outsourcing.php [NC,L]
And i m reciving this error:
Not Found
The requested URL /outsourcing was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
RewriteEngine On
RewriteBase /
www.example.com/DEMO www.example.com/Demo or doing www.example.com/DEMO/page2
RewriteRule ^/(DEMO|demo|Demo)/(.*)$ demo.php?=$1 [NC,L]
RewriteRule ^/(DEMO|demo|Demo)$ demo.php [NC,L]
RewriteRule ^/(D|d)emo$ demo.php [NC,L]
or pass anything www.example.com/DeMo www.example.com/bob to demo.php
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ demo.php [NC,L]
you may want to test if your allowed .htaccess RewriteRule /*$ http://google.com [R][L]
here is a good way to do it with case insensitive method
EDIT:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ${lc:$1}.php [NC]
this way anything entered will be redirected to a php file.
edit : this way your js and css file can still run
RewriteRule ^/[Dd][Ee][Mm][Oo]/?(.*)$ demo.php [NC,L]
will redirect any capitalization of "Demo" to demo.php
First add this line in the <VirtualHost> section OR at the end of your httpd.conf file (to enable lc function in .htaccess for later use):
RewriteMap lc int:tolower
Then have these rules in .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC]
RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC]
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond ${lc:%{REQUEST_FILENAME}}.php -f
RewriteRule . ${lc:%{REQUEST_URI}}.php [L]
First rule in .htaccess is doing external redirect by making a URI of /index.php to /index
Second rule in .htaccess is doing internal redirect by makign a URI of /INDEX to /index.php by lowercasing the URI. Assuming you have filename index.php physically present.
That way you can always write URLs without .php extension.