Symfony 2 Redirect to url without www - php

I don't know how to redirect my symfony application from:
http://www.mysymfonyapp.com
to:
http://mysymfonyapp.com
Here is my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /mysymfonyapp.com/web/
RewriteRule ^(.*)$ index.php [QSA,L]
If I'm entering application without 'www' it works, but with 'www' it has redirects loop. I've tried asking google, but I didn't find anything.

Ok, I figured it out and answering for others.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mysymfonyapp\.com$ [NC]
RewriteRule (.*) http://mysymfonyapp.com/$1 [R=301,L]
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /mysymfonyapp.com/web/
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mysymfonyapp\.com$ [NC]
RewriteRule (.*) http://mysymfonyapp.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteBase /mysymfonyapp.com/web/ (you don't need declare RewriteBase if you have this code in mysymfonyapp/web/.htaccess)
RewriteRule ^(.*)$ app.php [QSA,L] #Remember to redirect app.php
</IfModule>

Related

RewriteRule for subfolder htaccess

My url blog is here http://localhost/tibiaservers_11.10.19/blog
And my posts should be working like the following. after blog/
http://localhost/tibiaservers_11.10.19/blog/marketing-tools
http://localhost/tibiaservers_11.10.19/blog/the-cyber-house-rules
why isn't it working?
here is htaccess
Options +FollowSymLinks
RewriteEngine On
# FOR LOCALHOST RewriteBase /tibiaservers_11.10.19/
# FOR PRODUCTION RewriteBase /
RewriteBase /tibiaservers_11.10.19/
DirectoryIndex index.php
# przekierowanie na bez www
#RewriteCond %{HTTP_HOST} ^www\.tibiaservers\.net$
#RewriteRule ^/?$ "http\:\/\/tibiaservers\.net\/" [R=301,L]
<IfModule mod_rewrite.c>
# For Blog
RewriteRule ^blog/t-(.*)$ tagpost.php?id=$1 [L]
RewriteRule ^blog/c-(.*)$ catpost.php?id=$1 [L]
RewriteRule ^blog/a-(.*)-(.*)$ archives.php?month=$1&year=$2 [L]
# RewriteCond %{REQUEST_FILENAME} !-d [NC]
# RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^blog/(.*)$ viewpost.php?id=$1 [QSA,L]
##### - blog end
I think your RewriteRule should start with: ^tibiaservers_11.10.19/
This:
RewriteRule ^tibiaservers_11.10.19/blog/t\-(.*)$ tagpost.php?id=$1 [L]
Would match this url:
http://localhost/tibiaservers_11.10.19/blog/t-asdf
I use this tool for testing my .htaccess rules: htaccess.madewithlove.be

How to remove index.php from subdomain nested folder

I have main domain http://example.com on my root directory and all of my subdomains are in catalogs folder /catalogs/subdomain1,/catalogs/subdomain2.Currently my subdomain url in http://subdomain.example.com/index.php
I want to remove index.php from my subdomain.
My Root .htaccess file code is
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect on https:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
My Subdomain .htaccess
RewriteEngine on
# Redirect on https:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Options -Indexes
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Please use below code and update RewriteBase /root_directory/subdomain_folder_name/ at your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /root_directory/subdomain_folder_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
I hope this will helpful for you.
Try this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://subdomain.example.com/$1 [R=301,L]
RewriteRule ^$ folder [L]
DirectoryIndex index.php

URL rewriting with Wordpress Rewrite or .htaccess

I'm trying to append to wordpress an additional parameter into my URL.
For example, I have the URL: http://example.com
I want to change that to URL: http://example.com/this-example/
I'm thinking I can do this is in htaccess along the lines of a rewrite condition, but i'm unsure how to go about this. This is what I was thinking here.
Htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine on
RewriteRule ^/this-example/(.*)/ /index.php?$1 [L]
</IfModule>
Options -Indexes
You can try this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} !^/this-example [NC]
# use your own host here, for me is 192.68.10.10
RewriteCond %{HTTP_HOST} 192\.168\.10\.10$ [NC]
RewriteRule !^this-example/ /this-example%{REQUEST_URI} [L,R,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^this-example/(.*)$ $1 [L,QSA]
</IfModule>
Options -Indexes

HTTPS and Remove index.php on CodeIgniter

I am using codeigniter framework,set .htaccess file to remove index.php and trying to enable HTTPS protocol for the server, and something happened.
HTTP:
Everything is okay, when I access http://www.example.com/controller/method or http://www.example.com/index.php/controller/method
HTTPS:
Everything is okay, when I access https://www.example.com/index.php/controller/method
Got 404 not found when I access https://www.example.com/controller/method
I think that is .htaccess file problem, it is look like htaccess file not working for HTTPS protocol.
.htaccess file of my site.
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
Is something wrong? thanks a lot.
Note: The SSL rewrite should happen before the index.php rewrite in your .htaccess file.
So, Don't do this setting (as we don't change anything in server apache config file.
)
AllowOverride All
just apply the Setting 2 it works.
I have faced the same issue and resolved it by adding
AllowOverride All
Setting 1:
FYI we have 2 config files.
Default Apache config (which runs with http)
SSL config (which runs with https)
Go to SSL config and add
<Directory "/var/www/html">
AllowOverride All
</Directory>
**Setting 2:**The .htaccess file should be like this...
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
It worked for me.
First you remove $config['base_url] from your config file and put ''(blank) in your $config['index'] attribute ..
please set your .htaccess file like..
<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>
Try this
I used this in one of my project. May its helps you
#AuthType Basic
#AuthName "restricted area"
#AuthUserFile /home/site_name/public_html/.htpasswd
#require valid-user
RewriteEngine On
#RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.site_name.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?.site_name.lk$ [NC]
RewriteRule ^(.*)$ https://www.site_name.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?site_name\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? https://www.%1site_name.com%{REQUEST_URI} [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond $1 !^(index\.php|assets|files|robots\.txt)
# RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Note site_name in the above htaccess should replaced to your website name
you can try this, it works for my project.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
reference: https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
if you want to http->https AND remove www AND remove index.php here's the solution:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>

Redirect sub-domain all post to main domain

I want to redirect all posts that are on subdomain to live domain.
For example, www.blog.mydomain1.com/post-1 to www.mydomain1.com/post-1
I try this htaccess code , It redirect the main subdomain but it does not redirect the post links
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.mydomain1\.com$ [NC]
RewriteRule ^(.*) http://www.mydomain1.com/$1 [R=301,L]
My Complete HTAccess is
# 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
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [NC,R,L]
# BEGIN MainWP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/plugins/mainwp-child/(.*)$ /wp-content/plugins/THIS_PLUGIN_DOES_NOT_EXIST [QSA,L]
</IfModule>
# END MainWP
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [NC,R,L]
Clear your browser cache before testing this Redirect.

Categories