Need change inside htaccess file - .htaccess

i have following htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule !^/?(maintenance\.html|.*\.css|.*\.js)$ http://www.example.com/maintenance.html [R=302,L]
RewriteRule ^([A-Za-z0-9]+)$ $1.php
RewriteRule ^home\.php$ index.php
RewriteRule ^home$ index.php
as you can see all, no matter which page you visit on the website it will be redirected to maintenance.html. I also need a small change that will exclude one more location from this. Since I am using Magento, I need to exclude admin area from this redirect so I think these are the urls that I need
http://www.example.com/index.php/admin_852_in
http://www.example.com/skin/
http://www.example.com/js/
http://www.example.com/media/
What rule should I add for these two urls too?
thanks!

You can tweak your exclusions like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule !^/?(maintenance\.html$|index\.php/admin|css/|js/|.*\.(css|js)$) http://www.example.com/maintenance.html [R=302,L,NC]

Related

htaccess friendly urls 3 parameters

I've got an address like this:
/?pid=74&sid=381:naprawairegeneracjaturbosprezarek24hjozefkrezolek
and i want to have:
/74:381:naprawairegeneracjaturbosprezarek24hjozefkrezolek
or better:
/naprawairegeneracjaturbosprezarek24hjozefkrezolek
my .htaccess
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z]+):([a-z]+):([a-z]+)$ /index.php?pid=$1&sid=$2:$3 [L]
I have also rewrite rule to delete index.php from url
RewriteRule ^([0-9]+):([0-9]+):([a-z]+)$ /index.php?pid=$1&sid=$2:$3 [L]
You cannot achieve /naprawairegeneracjaturbosprezarek24hjozefkrezolek unless you make sure that index.php can find the correct item with only that parameter.

How to redirect a page without the page extension

I am currently working on a signup page and I was wondering if I could modify the URL without the .php extension.
For example, it is now
www.xyz.com/signup.php
And what I would like achieve is
www.xyz.com/signup
Now I am assuming that I might have to use the htaccess file, but I am not sure about it.
First rule will redirect from signup.php to domain.com/signup/.
Second rule will redirect internally so the URL will remain domain.com/signup/ while displaying the content of domain.com/signup.php.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Redirect /signup.php to /signup/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+signup\.php\s [NC]
RewriteRule ^ /signup/? [R=302,L]
# Internally forward /signup/ to /signup.php
RewriteRule ^signup/?$ /signup.php [NC,L]
What you're looking for is called URL rewrite. Take a look at this tutorial for beginners: http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/.
You can duplicate with .htaccess
RewriteEngine On
RewriteRule singup$ singup.php [NC,L]

Redirect a .jpg using .htaccess

I needed to redirect "example.com/image/img.jpg" to "example.com/view/img.jpg"
Therefore I've used
RewriteRule (^|.*?/)image/(.*)$ /$1view/$2 [R=302,L,NC]
But, still if I try to visit "example.com/image/img.jpg" it won't redirect. What am I doing wrong?
Thank you.
I needed to redirect "example.com/image/img.jpg" to "example.com/view/img.jpg"
Apparently the above examples are not accurate as your rule shows directories image and view can be at any level in the corresponding URL directory structures.
If that's the case, you may try this in one .htaccess file at root directory:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(.*)?image/([^.]+)\.jpg [NC]
RewriteRule .* /%1view/%2.jpg [R,L,NC]
In case image and view directories are indeed at the first level as described in the examples, replace the last 2 lines with this one:
RewriteRule ^image/(.*) /view/$1 [R,L,NC]
Replace [R,L,NC] with [R=301,L,NC] for permanent redirection or with [L,NC] for internal mapping.

Having much trouble with mod_rewrite

I'm having some problems in my .htaccess file.
I would like to display the content of this URL:
http://mywebsite.com/admin/payments/invoices/view/index.php?id=123456
When I access this one:
http://mywebsite.com/admin/payments/invoices/view/123456/
Here's my actual .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /admin/payments/invoices/
RewriteRule ^/view/([0-9]+)/(index.php)?$ /view/index.php?id=$1 [L,QSA]
Do you have any idea?
Thanks!
If you do have the view directory, then the easiest thing is to put this .htaccess in that directory (i.e. {DOCUMENT_ROOT}/admin/payments/invoices/view/.htaccess):
Options +FollowSymlinks
RewriteEngine On
RewriteBase /admin/payments/invoices/view
RewriteRule ^(\d+)$ index.php?id=$1 [L,QSA]
The index.php in the left side hand of the RewriteRule is not required (actually, I expect it not to work: the DirectoryIndex should not yet have been injected in the URI at this stage - unless some other RewriteRule is in effect?), nor is the / at the end of the RewriteBase.
I tested the above on Apache/2.2.21, but the module rules are the same for later versions.
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*admin/payments/invoices/view/index\.php\?id=([0-9]+) admin/payments/invoices/view/$1/index.php [L]
</IfModule>
Try putting this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)id=([0-9]+)
RewriteRule ^admin/payments/invoices/view/index\.php$ /admin/payments/invoices/view/%1/index.php [L]
So when you enter http://mywebsite.com/admin/payments/invoices/view/index.php?id=123456 in your browser's URL address bar, you will get served the content at /admin/payments/invoices/view/123456/index.php. Since it's completely unclear what you actually want, in case you wanted it the other way around:
RewriteEngine On
RewriteRule ^admin/payments/invoices/view/([0-9]+)/(index.php)?$ /admin/payments/invoices/view/index.php?id=$1 [L,QSA]

.htaccess php to html only in root

I been using .htaccess to change php to html and it works great, but I hit a snag when I forgot that some of my static html pages in subfolders don't appear in the web browser.
Is there a way I can make it so I can only have the root folder uses the .htaccess rule and not the subfolders?
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L]
For this case define your .htaccess rule like this:
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteRule ^(?![^/]+/)(.+)\.html$ $1.php [L]
Negative lookahead will prevent sub directory rule implementation.
You can specific a rule to work only on current dir. Like:
/your/dir/here/.htaccess
You .htaccess will be:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\/here(.*)\.html$ $2.php [L]
$2 mean get second group.
Edit: alternativaly, you can make a .htaccess on subfolder and disable RewriteEngine.

Resources