mod_rewrite to change query data - mod-rewrite

I have two files in a folder called MyFolder: index.php and members.php
I specify the member in members.php like so
members.php?member=member1
I would rather just write something like this in the browser:
MyFolder/member1
index.php should be unaffected
What do I write in my .htaccess file to make this happen?

Try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /member.php?member=$1 [L]
RewriteRule ^/?$ /index.php [L]
You can put that in the "myfolder" folder.

You could try something like:
RewriteEngine on
RewriteRule ^/myfolder/(.*) /myfolder/member.php?member=$1 [L]
RewriteRule ^/myfolder/?$ /myfolder/index.php [L]

Related

How to redirect all pages only to index.html using htaccess file and not redirect the image files

How to redirect all pages (pages only) to index.html using htaccess file and not redirect the image files. For some reason I am using this code and an image file on the index.html page isn't showing up.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .* /index.html [L,R=302]
Try this code :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /index.html [L,R=302]
Keep your rules simple. Instead of filtering what shouldn't match, just match on the files.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .*\.(php|html)$ /index.html [L,R=302]
A nicer way might be just to ignore existing files. For example:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* / [L,R=302]
The !-d says to ignore the rewrite if there is an existing directory that meets the match.
The !-f says to ignore the rewrite if there is an existing file that meets the match.
Everything else will get rewritten.
You need to add a .htaccess file inside the public directory, so whenever you build your app, it automatically gets copied to the new dist directory. The content of.htaccess should be like:
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
Add the following before the last line
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$

.htaccess file for magento in subdirectory

We are finding it difficult to remove the redirection of my /admin to /index.php/admin, which is not allowing us to access the admin panel, at every url that should start with /admin/ gets redirected to /index.php/admin/ and it displays No input file specified. and when i remove index.php from the url it works fine.
My .htaccess file looks like this
DirectoryIndex /new/magento-k/index.php
RewriteEngine on
RewriteBase /mysubdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteCond %{REQUEST_URI} !^/admin.*
RewriteCond %{REQUEST_URI} ^/index.php/admin.*$
RewriteRule ^/index.php/admin(.*) /admin$1 [R]
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^/index.php/(admin|user)($|/) - [L]
Options -MultiViews
Try putting this into your .htaccess file
RewriteRule .* /index.php [L]
and remove the other index.php rule:
RewriteRule ^/index.php/(admin|user)($|/) - [L]
Also make sure to clear cache of Magento and your browser.

Codeigniter mod_rewrite for both root and subdirectory

I have:
root/.htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
it works perfectly send all request(except file and folder) to index.php. I need it to work to my subfolder too.
I have .htaccess in subfolder root/demos/project contain:
RewriteOptions inherit
but doesn't work.
I try this in root/.htaccess
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteRule ^demos/project/(.*)$ demos/project/index.php/$1 [QSA,L]
Doesn't work.
this:
RewriteRule ^demos/project/(.*)$ demos/project/index.php/$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
get Internal Server Error 'missconfiguration'
and many several way, but everything I tried, I just get these: 501(default from server) and 404(from ci in root);
I use codeigniter in both root and demos/project and just want to 'hide' index.php from both, how to do this correctly ?
Thanks.
RewriteEngine on
RewriteRule ^(.*)$ /demo/project/index.php?/$1 [L]
does that work?
You could also just place another .htaccess in your demo/project folder.
EDIT:
try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /demo/project/index.php?/$1 [L]
EDIT2:
If you get a 404 not found page just change your config.php in root/application/config/config.php from the following:
$config['index_page'] = "index.php";
to:
$config['index_page'] = "";

AJAX rewrite rule for directories

I'm trying to write a rewrite rule in addition to wordpress's :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I would not like everything to redirect to the main page. I have multiple sub-directories which need to be redirected too : http://www.example.com/sub1 and http://www.example.com/sub2. I'm doing this so my content can be loaded via Ajax.
I thought this would simply be
RewriteRule ^/(sub1|sub2)/(.*)$ http://www.example.com/$1/ [L]
Which I placed in the block here:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(sub1|sub2)/(.*)$ http://www.example.com/$1/ [L]
RewriteRule . /index.php [L]
</IfModule>
Perhaps with wordpress you must use wp_rewrite_rule? I figured I could mess with the .htaccess file, get my rule to work, then move it over to functions.
any help would be appreciated.
Thanks.
UPDATE:
I've also tried to set the .htacces file back to the wordpress default... and add this code to the functions.php file for my child theme:
function AJAX_rewrite_rule() {
add_rewrite_rule(
'^/(sub1|sub2)/(.*)$',
'http://www.example.com/$1',
'top' );
};
add_action( 'init', 'AJAX_rewrite_rule' );
Seems to slow the load of everything down, but all files not found are still redirected to the main page, not the subdirectory.
UPDATE #2
I think I was going the wrong direction, as add_rewrite_rule is only to add a rule to the structure already put in place by wordpress. This all works by interpreting URL's, and changing them to variables for a DB query run by index.
I'm pretty sure I need to use $wp_rewrite->non_wp_rules. If anyone has more of an idea, let me know.
Try this, you seem to have ine bad line there:
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteBase /
# RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f #Means DONT redirect if file exists.
RewriteCond %{REQUEST_FILENAME} !-d #Means DONT redirect if directory exists.
RewriteCond %{REQUEST_URI} !^/sub1/
RewriteCond %{REQUEST_URI} !^/sub2/
# RewriteRule ^/(sub1|sub2)/(.*)$ http://www.example.com/$1/ [L]
RewriteRule . /index.php [L]
</IfModule>
What happens is, every time you add a "RewriteRule" all the "RewriteCond" are applied to that rule, and then you start with a blank slate:
RewriteCond A
RewriteCond B
RewriteCond C
RewriteRule Whatever [L] #This applies A, B, and C
RewriteRule Another [L] #This applies no rules
Perhaps that will help.
Also, you may try adding your "RewriteRule ^/(sub1|sub2)/(.*)$ http://www.example.com/$1/ [L]" right after "RewriteEngine On" if that doesn't work…

double redirect mod_rewrite

I am trying to configure a .htaccess file to my webpage to make it work as i want, but after a lot of searching and trying to understand the documentation, my head is just confused about these mod_rewrite.
It looks like this:
root/index.php
root/application/-subfolders-
root/config/-files-
root/library/-files-
what i want is everything sent to the index.php file as a parameter like index.php?page=$i, so i can have links like www.mypage.com/foo/bar and my index.php handles it.
ALSO i want to have the www.mypage.com/js/filename be sent to a subfolder in application,
like root/application/javascripts/filename.
I just cant get this to work, tried different answer i found both here and other places.
.htaccess at is now:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/js/ application/javascripts/ [L]
RewriteRule ^/js/(.*)$ application/javascripts/$1 [L]
RewriteRule ^css/ application/css/ [L]
RewriteRule ^css/(.*)$ application/css/$1 [L]
RewriteRule ^images/ application/images/ [L]
RewriteRule ^images/(.*)$ application/images/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php?page=$1 [NC]
</IfModule>
This should do it:
RewriteEngine on
RewriteRule ^js/(.*)$ application/javascripts/$1 [L]
RewriteRule ^css/(.*)$ application/css/$1 [L]
RewriteRule ^images/(.*)$ application/images/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [NC]

Resources