newbie trying to write url rewrite in .htaccess file - apache

My site was under example.com/waha/.
Now I move the site right under the root example.com.
I want to 301 redirect all the old links like example.com/waha/notice/5803 to example.com/notice/5803.
How can I do it?
My current .htaccess file is below.
<IfModule mod_rewrite.c>
RewriteEngine On
# NOTE: change this to your actual StatusNet path; may be "/".
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?p=$1 [QSA,L]
</IfModule>
<FilesMatch "\.(ini)">
Order allow,deny
</FilesMatch>
Options -Indexes

Try this rule in front of your other mod_rewrite rule:
RewriteRule ^waha/(.*) /$1 [L,R=301]

Related

.htaccess file wont redirect to /public folder (laravel issue)

I have folder /var/www/html/project/himp and there is my laravel installation.
In /var/www/html/project is my landing page index.html and some css files.
Inside /himp folder I have .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
also in /himp/public folder I have also .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Now when I go to the domain.com/himp/public I get Laravel installation and startup screen but when I go to the domain.com/himp I get just folder views, so there is no redirection to public folder ...
Why? What can be a problem here? Please help.
Contrary to the pattern in RewriteRule (see "What is matched?"), the variable REQUEST_URI contains the full path, including /himp. So the condition should be either
RewriteCond %{REQUEST_URI} !/public
without a beginning of string anchor ^, or you must include the full path
RewriteCond %{REQUEST_URI} !^/himp/public

htaccess mod_rewrite. error 404 page not found. Help Fix?

I am having issues getting mod_rewrite to work. I have an image sharing site, but currently the image URL given leads to a 404 page. This is because the htaccess is not rewriting the urls correctly (or the code is not paired up to the htaccess file.
URL: http://danielardley.com/imgupl/img-579bad054a164.html
htaccess file:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?danielardley\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ nohotlink.gif [L]
<Files ~ "\.(php|sql|php3|php4|phtml|pl|py|jsp|asp|htm|shtml|sh|cgi)$">
order allow,deny
deny from all
</Files>
the site is hosted on a sub dir of the domain, would that cause an issue?
Bro You Neeb Add This Code In hataccess # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress To Delete Index Of To You Website Look

Symfony .htaccess adding rule for app_MYNAME.php

i want to add another app_MYNAME.php in the web folder.
This file is nearly identical to the app.php.
The only difference is this entry:
$kernel = new AppKernel('MYKERNELNAME', false);
I want to load different configuration files with these method.
When i type in the browser:
domain.de/app_MYNAME.php/VALUE
all is fine.
Now i want to hide the app_MYNAME.php. The Result should look like:
domain.de/VALUE
The second step is the redirecting. When someone type in the browser:
domain.de/MYNAME/VALUE
it should be redirected to:
domain.de/app_MYNAME.php/VALUE
I only get a 404 or a misconfigured message.
At the end i need 3 app_MYNAME.php files (app_MYNAME1.php, app_MYNAME2.php, app_MYNAME3.php).
I hope someone could explain me, what to put in the .htaccess file.
Here is my .htaccess file:
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
Try with a configuration that looks like this in your .htaccess file :
<IfModule mod_rewrite.c>
RewriteEngine On
# ... Your other stuff
# RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.*)$ /app_MYNAME.php [QSA,L]
</IfModule>
Also, make sure that your nginx/apache host file is pointing to the web directory of your Symfony project.
Try this :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_MYNAME.php [QSA,L]
Maybe all app.php could convert to app_MYNAME.php in your htaccess

.htacces redirect all traffic to index.php and request for .js to another file

Hi Im Not very comfortable writing htaccess rules, my goal is
Redirect all traffic to index.php
Redirect all request to script.min.js to script.php
ultimately scripts.min.js does not exist rather the script.php will have set headers and include all needed JS files to create one master file. Also the status code should be 200.
Thank you in advance
I haven't tested this, but it'd probably look something like:
RewriteEngine On
RewriteRule ^script.min.js$ script.php [L]
RewriteCond %{REQUEST_URI} !/index.php$ [NC]
RewriteRule (.*) /index.php [L]
I was able to solve the problem by taking wordpress .htaccess and prepending the file match section
<IfModule mod_rewrite.c>
RewriteEngine On
<FilesMatch "\.(js)$">
RewriteRule . /scripts.php [L]
</FilesMatch>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

How can I remove "index.php" from my links?

Normally I access a page like this: http://localhost/codeigniter/index.php/auth/login
However I want to be able to access to the page like this : http://localhost/codeigniter/auth/login
I have no information about http.conf and .htaccess configurations.
I have set $config['index_page'] = ''; in codeigniter/application/config/config.php
my http.conf file is at its default except uncommentnig "LoadModule rewrite_module modules/mod_rewrite.so"
I inspected many proposed .htaccess files but I could not understand the logic behind the rewriting rules.
Here is the most successful .htaccess content for me. It is located at /www/CodeIgniter/ .
(by the most successful I mean that this is the only one that gives 404 error created by the CodeIgniter not by the server.)
RewriteOptions Inherit
Options -Indexes
Options +FollowSymLinks
RewriteBase /CodeIgniter/
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(images|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
I hate requesting direct solutions however unfortunately, it is my last resort :/
Can you give me a right solution to my problem?
It's my repeat answer:
Codeigniter issues with paths in localhost (XAMPP)
please create .htaccess file in project folder and write:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
You don't need to define in base_url in config file:
$config['base_url'] = ''; // blank it.
put this on your htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
make sure the rewrite module is enabled on your server
This is the simplest one i found which works for me :-
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]