i have the following .htaccess
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?type=Navigation&action=$1
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?type=Navigation&action=$1
Options All -Indexes
which sends everything to index.php in the root folder. But in my structure i have something like
/root
/.htaccess
/index.php
/files
/intranet
i was wondering if there is a RewriteRule exception so that when i type www.mysite.com/intranet it goes to the 'intranet' folder without passing trough the index.php file
thanks!
Yes. I believe you just put a rule before the others with the url you do not want rewritten, and specify that it shouldn't be rewritten using - like so:
RewriteRule ^intranet/.*$ - [L]
RewriteCond %{REQUEST_URI} ^\/intranet\/?
RewriteRule ^([a-zA-Z0-9_-]+)\/?$ index.php?type=Navigation&action=$1 [L]
Will do the trick.
Related
I'm getting to know more about .htaccess, Apache & httpd config file. I have 2 files:
index.php
page.php
Both in the same folder
I already succeed to rewrite the index.php?site= to example.com/sitename. But when I try to add a rewrite which has to look like example.com/sitename/article/2 which redirects to page.php?site=sitename&page=pageid,
the rewrite does not work. I think this is because of the previous redirect example.com/sitename
But I like to have them both in my .htaccess file.
My current code is
RewriteEngine On
RewriteRule ^(admin)($|/) - [L]
RewriteRule ^([a-zA-Z0-9-/+]+)$ index.php?site=/$1 [L,QSA]
RewriteEngine On
RewriteRule ^(admin)($|/) - [L]
RewriteRule ^([a-zA-Z0-9-/+]+)$ index.php?site=/$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9-/+]+)$ index.php?site=/$1/Article/&page=$2 [L,QSA]
As you can see in the last code example I added has to go to:
example.com/Sitename/Article/2
how to write RewriteRule to access php file as html extension, the mark file is located inside folder called domain.com/markfolder/mark.php
and i got following in my root directory
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RedirectMatch 301 (.*)\.html$ $1.php
and below file i try to locate inside domain.com/markfolder/.htaccess
try 1
RewriteEngine on
RewriteRule ^mark\.php$ mark.html [NC,R]
try 2
RewriteEngine on
RewriteRule ^(.*)\.html $1\.php
try 3
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.+)\.html$ $1.php [NC,L]
above three try simple doesn't work.
First, your htaccess file in your root directory is causing the problem. It's redirecting .html to .php and is part of mod_alias, not mod_rewrite. This means requests will get processed by both the RedirectMatch as well as any rewrite rules. So first change your root htaccess to:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L,R=301]
Not sure why you want to permanently redirect, since this will affect all requests even requests in subdirectories. It seems like it's not what you want and will only break any attempt for you to rewrite.
Then in the htaccess file in your markfolder:
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]
I m sure that many people will say that this is duplicated but I try everything from other "Question"`s and nothings work for me.
The problem is that I move my project to the web server.
In this server I have folder "public_html" where I but my project Symfony.
Now to enter on my project I must write the following url: www.mydomain.com/Symfony/web/*
But I want to write a Rewrite Rule which will redirect from www.mydomain.com/Symfony/web/* to
www.mydomain.com/home/*.
To do this I try on 2 different ways with many combination of ReWrite rule.
In my public_html I create a .htaccess folder
I edit the .htaccess in Symfony/web folder
I add the following rule in both file but without success
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Symfony/web/(.*)$ www.mydomain.com/home/$1 [L,R=301]
Unfortunately without success. What I`m doing wrong?
My htaccess file look like
And all the time Error 404 Object not found
Symfony/web/.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteRule ^home/(.*)$ $1 [L,NC]
</IfModule>
It`s redirecting me but I receive again Object not found :(
I delete the .htaccess in public_html folder which is the root one for my server
public_html\.htaccess
RewriteEngine On
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
1: Place this code in /Symfony/web/.htaccess:
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [L]
2: Place this code in /public_html/.htaccess:
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
I'm going to go out on a limb and say that your rule is backwards. I think you want your URL to be www.mydomain.com/home/* in the browser... In which case the rule would be reversed. Also, your .htaccess should be in the root and you don't need to include the domain in the rewrite rule because you set a rewrite base.
RewriteRule ^home/(.*)$ Symfony/web/$1 [L,R=301]
I cant understand how to redirect to the parent directory in this case:
I have a root directory with .htaccess file, where rewriteEngine is on. In this directory I have a file rootFile.php.
Also, in this directory I have a directory "forum", with another .htaccess file in it.
When there is request to "forum.mySite.com/rootFile.php", I need to redirect it to "mySite.com/rootFile.php" which means I need to redirect request to the parent directory.
/forum/.htaccess:
RewriteEngine on
RewriteBase /forum/
RewriteRule ^sitemap /forum/map.php [L]
...
I tried to:
RewriteEngine on
RewriteBase /forum/
RewriteRule ^rootFileName ../rootFile.php [L]
\# or so RewriteRule ^rootFileName /rootFile.php [L]
\# or so RewriteRule ^rootFileName rootFile.php [L]
RewriteRule ^sitemap /forum/map.php [L]
Also tried this one:
RewriteEngine on
RewriteBase /
RewriteRule ^rootFileName ../rootFile.php [L]
\# or so RewriteRule ^rootFileName /rootFile.php [L]
\# or so RewriteRule ^rootFileName rootFile.php [L]
RewriteBase /forum/
RewriteRule ^sitemap /forum/map.php [L]
And it always redirect from /forum/rootFileName to /forum/rootFile, but never to /rootFile.
Where is my mistake?
You can't rewrite to outside the document-root. This is a security thing.
You could just create a rootFile.php that only contains <?php include('../rootfile.php'); ?>
You can't rewrite to paths that are outside your document root for security reasons. In fact this should be avoided because it is not a good practice.
Anyway, to answer your question, a workaround might be creating a symlink in your document root that points to the target/parent directory, but you should protect it from direct accesses.
Let me do an example. Assume that our document root is /var/www/project1 and that you want to rewrite on /var/www/project2/target.php
Then, you have to create a symlink inside /var/www/project1 that points to /var/www/project2 named (for example) p2.
This should be your /var/www/project1/.htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} /hello/world
RewriteRule ^(.*)$ p2/target.php [QSA,L] # p2 is the symlink name!
</IfModule>
You wrote:
When there is request to "forum.mySite.com/rootFile.php", I need to
redirect it to "mySite.com/rootFile.php" which means I need to
redirect request to the parent directory.
Did you mean:
When there is request to "mySite.com/forum/rootFile.php", I need to
redirect it to "mySite.com/rootFile.php" which means I need to
redirect request to the parent directory.
...Which in turn means:
When there is request to "/forum/rootFile.php", I need to
redirect it to "/rootFile.php" which means I need to
redirect request to the parent directory.
In your .htaccess in the /forum dir try this:
RewriteEngine On
RewriteRule ^rootFileName(.*) /rootFile.php [QSA,R=301,L]
I am trying to write RewriteRule to redirect www.myweb.com/download/blabla.zip to > www.myweb.com/download/download.php?filedownload=blabla.zip
this is my .htaccess
Options +FollowSymlinks
RewriteBase /download/
RewriteEngine on
RewriteRule ^(.*)$ download.php?filedownload=$1 [L]
the .htaccess located in the folder /download
and the download.php file located also in the folder /download
but it doesnt work, no idea why...
Can you help me?
BTW: the mod_rewrite is enabled.
Thanks.
Your RewriteRule is recursing on itself, and passing download.php as the parameter to itself.
You can try either of the following.
To match only zip/exe:
RewriteRule ^(.*\.(zip|exe))$ download.php?filedownload=$1 [L]
To exclude download.php from matches, place this before your RewriteRule:
RewriteCond %{REQUEST_FILENAME} !download.php