.htaccess not working, what am I doing wrong? - .htaccess

So i have an .htaccess file that has this in it:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [NC,L]
When I go to /path/to/app/ in the browser it displays the directory structure instead of redirecting the server to /path/to/app/public/$1
What am I doing wrong?

Problem is this line:
RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [NC,L]
Remember: Rewrite doesn't match leading slash. Change your rule to this:
RewriteEngine On
RewriteBase /
RewriteRule ^(path/to/app)/(.*)$ /$1/public/$2 [NC,L]

I think you try build Symfony application? To rewrite rule you need allow override in httpd.conf
DocumentRoot "/var/www/symfony/web"
<Directory "/var/www/symfony/web">
allow from all
AllowOverride All <-------------
Options +Indexes
</Directory>
And if you use directive
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
that mean that if directory exist then display structure else use other RewriteRule
Also try
RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [QSA,L]

Related

htaccess redirect to subfolder with url paramethers

I want to redirect every requests to my public/index.php file. i've tried
RewriteEngine On
RewriteRule ^(.*)$ public/index.php?url=$1
code that seems fine but its not working. my goal is change url form http://example.com/?url=user/profile/2 to http://example.com/user/profile/2.
my directory structure is
root
public
index.php
vendor
.htaccess
composer.json
To handle URLs like: http://example.com/user/profile/2 please try following Rules sets in your .htaccess file. Place your htaccess rules file into root directory. Please make sure to clear your browser cache before testing your URLs.
Options -MultiViews
RewriteEngine ON
RedirectBase /ApadanaCMS/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ public/index.php?url=$1/$2/$3 [L]
OR try following rules, please make sure either try above OR following rules at a time only.
Above will work for non-existing pages, to make it for any url(like you mentioned in your question) try:
Options -MultiViews
RewriteEngine ON
RedirectBase /ApadanaCMS/
RewriteCond %{REQUEST_FILENAME} !index\.php [NC]
RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ public/index.php?url=$1/$2/$3 [L]
heres the solution:
uncoment (remove # ) mod_rewrite.so module in httpd.conf file in apache2 (in my case c:\Apache24\conf\httpd.conf) file. also change AllowOverride none to AllowOverride All in that file under DocumentRoot "${SRVROOT}/htdocs" section.
and this is .htaccess content
RewriteEngine on
RewriteRule ^(.*)$ public/index.php?url=$1 [QSA,L]
RewriteRule ^()$ public/index.php?url=$1 [QSA,L]
however if you need to get static files in your static directory add a new .htaccess file inside static directory with RewriteEngine off content

URL rewrite replace string

I am trying to replace a word in URL and redirect the user using .htaccess
I have this link,
/anyword/akram/anyotherword
and I would like to redirect user to
/anyword/tanger/anyotherword
Here is the code I have tried
RewriteRule ^(.*)akram(.*)$ $1tanger$2 [R=301,L]
Edit
Virtualhost:
<Directory /var/www/html/mywebsite.com/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.+)/akram/(.+)$ http://%{HTTP_HOST}/$1/tanger/$2 [R=301,L]
</IfModule>
</Directory>
</VirtualHost>
You can try this rule.
RewriteRule ^(.+)/akram/(.+)$ http://%{HTTP_HOST}/$1/tanger/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
you should create a new file and save it as .htaccess
After that . Edit the contents of the file. For 301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis.
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://***/anyword/tanger/anyotherword
I'm answering quite late.
but I think somebody can get it helpful..
RewriteEngine on
RewriteRule /akram/ /tanger/
checkout
Open link, and click on "test"

Codeigniter URL rewriting .htaccess is not working on CentOS

I've created a .htaccess file in my document root at /var/www/html/ to rewrite URL of Codeigniter to remove "index.php" from URL of all pages.
e.g. Change URL from
http://myhost/index.php/controller/function
to
http://myhost/controller/function`
Here is the code of my `/var/www/html/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I've got many suggestions from googling to enable mod-rewrite module, but I can see in my httpd.conf its already enabled.
LoadModule rewrite_module modules/mod_rewrite.so
This is perfectly working on my local system running on Debian 7 (Apache/2.4.4).
Any help would be appreciated. :)
You need to also specify the locations that can use it. For example, in /etc/httpd/conf/httpd.conf you should see something like:
<Directory "/var/www/html">
...lots of text...
</Directory>
Make sure is has:
<Directory "/var/www/html">
AllowOverride All
</Directory>
It's possible that your centos server isn't setup to handle PATH INFO. Try replacing the index.php/$1 in your rule's target to index.php?/$1.
Then you need to modify your CI config to enable query strings: http://ellislab.com/codeigniter/user-guide/general/urls.html
In you application/config.php file set $config['enable_query_strings'] to TRUE.
# CentOS Linux release 7.9.2009 (Core) -
# CodeIgniter 3.1.11 - ( .htaccess - This code work for me )
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

.htaccess variables REWRITING but not REDIRECTING

I've been looking for my answer for 2 days but since I haven't found it, I finally decided to put my question to you.
I'm using a Brinkster shared host and can access the .htaccess but no Apache configuration. Every folder on the server represents the content of one site (domain). In the root I have a .htaccess where every domain is controled with
RewriteCond %{HTTP:Host} ^(?:www\.)?domainname\.be$
RewriteRule (.*) /folder/$1 [NC,L,NS]
In the folder I have another .htacces file.
I want to rewrite and redirect for prettier URLs
http://www.domainname.com/pag.asp?name=var_name&id=var_id
should look like
http://www.domainname.com/name/
The rewrite bit works with the .htaccess code bellow.
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks -MultiViews
Options FollowSymLinks
AllowOverride All
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^name=([a-zA-Z-]+)&id=([0-9]+)$ [NC]
RewriteRule ^/?page\.asp$ /%1? [R=301,L]
</IfModule>
But for some reason www.domainname.com/name/ always gives a 404.
What am I doing wrong?
Any help wouldd be highly appreciated.
Thank you

.htaccess: Redirect root url to subdirectory, but keep root URL structure

I have created a site in a subdirectory and would like the site to appear as if it's in the root.
I used the below Mod_Rewrite code to get the site root to redirect to the subdirectory, but I would like the folder the files are held in to not appear.
currently: www.example.com/sitefiles/content/
Would like: www.example.com/content
Thanks
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^$ /sitefiles/ [L]
RewriteRule (.*) /sitefiles/$1 [L]
If it needs to be done via .htaccess and mod_rewrite, then use this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/sitefiles/
RewriteRule (.*) /sitefiles/$1 [L]
Since you do not explicitly specify the page when website root will be hit, then there is no need for this line: RewriteRule ^$ /sitefiles/ [L]
You need to add condition for your main rewrite rule to prevent rewrite loop (when already rewritten URL gets rewritten again): RewriteCond %{REQUEST_URI} !^/sitefiles/
Well, the directory should have no reason to appear in any listing, and that mod_rewrite you posted should allow you to do as you said. Still, I would go about it a different way:
Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^$ sitefiles/ [L]
RewriteRule ^(.+)$ sitefiles/$1 [L]
Hope this works.

Resources