Symfony .htaccess adding rule for app_MYNAME.php - apache

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

Related

Alternative procedure to prerender(not using prerender.io) in htaccess. Full custom code recommended

Is there any alternative procedure not to use prerender.io or custom way to implement it by writing code in htaccess? Need help. I am using angular 4 and apache server in back. Prerender.io asking for subscriptions.Please if anyone can help me writing the same custom code in htaccess.Here is my code in htaccess.
<IfModule mod_headers.c>
RequestHeader set X-Prerender-Token "xxxxxxxxxxxxxxxxxx"
</IfModule>
<IfModule mod_rewrite.c>
DirectoryIndex
RewriteEngine on
# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Options +FollowSymLinks
#RewriteRule ^api/(.*)$ http://weedbuys.com/api/$1 [P,L]
# Prerender.io stuff
<IfModule mod_proxy_http.c>
RewriteCond %{HTTP_USER_AGENT} Baiduspider|DoCoMo|Twitterbot|
TweetmemeBot|Twikle|Netseer|Daumoa|SeznamBot|Ezooms|MSNBot|Exabot|MJ12bot|sogou\
sspider|bitlybot|ia_archiver|proximic|spbot|ChangeDetection|NaverBot|MetaJobBot|magpiecrawler|Genieo\sWeb\sfilter|Qualidator.com\sBot|Woko|Vagabondo|360Spider|ExB\
sLanguage\sCrawler|AddThis.com|aiHitBot|Spinn3r|BingPreview|GrapeshotCrawler|
CareerBot|ZumBot|ShopWiki|bixocrawler|uMBot|sistrix|linkdexbot|AhrefsBot|archive.
org_bot|SeoCheckBot|TurnitinBot|VoilaBot|SearchmetricsBot|Butterfly|
Yahoo!|Plukkie|yacybot|trendictionbot|UASlinkChecker|Blekkobot|Wotbox|YioopBot|
meanpathbot|TinEye|LuminateBot|FyberSpider|Infohelfer|linkdex.com|Curious\sGeorge|FetchGuess|ichiro|MojeekBot|SBSearch|WebThumbnail|socialbm_bot|SemrushBot|Vedma|alexa\ssite\
saudit|SEOkicks-Robot|Browsershots|BLEXBot|woriobot|AMZNKAssocBot|Speedy|oBot|
HostTracker|OpenWebSpider|WBSearchBot|FacebookExternalHit [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
# Only proxy the request to Prerender if it's a request for HTML
RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|
\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.
mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.
dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent))(.*) http://service.prerender.io/http://weedbuys.com/$2
[P,L]
</IfModule>
# Don't rewrite files or directories, but exclude adminer directory
RewriteRule ^(adminer)($|/) - [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^adminer - [L,NC]
RewriteRule ^ index.html [L]
</IfModule>

.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>

.htaccess web/ + secure directory 1and1 Webserver

I am running symfony2.3. My .htaccess looks like this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteRule ^/web/ - [L]
</IfModule>
I always have to enter www.example.com/web/en/. How can I get rid fo web/ ?
I also can get to files to www.example.com/composer.json. This should not happen. How can I secure it?
TIA!
Changing this line
RewriteRule ^/web/ - [L]
to
RewriteRule ^/ - [L]
should help with the first issue.
The second issue isn't possible if that file is used on a webpage. If a browser can access it then a user can.
This works.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /web/$1 [QSA,L]
</IfModule>
But now I have www.example.com/de/ also www.example.com/web/de/. Is there a way to have only the first was?

htaccess for symfony2 in shared hosting

i have a shared hosting.
I want to see a example of .htaccess file in public_html folder to setup a symfony2 application(the entry point is web/app.php)
Thanks a lot in advance
The symfony standard edition already contains a .htaccess which you can use.
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [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 this:
DirectoryIndex public_html/app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public_html/
RewriteRule (.*) /public_html/$1
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /public_html/app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
Set it up on the root folder, one level above public_html.

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]