Menu
  • HOME
  • TAGS

Sitemap in Laravel application

Tag: .htaccess,laravel,seo,sitemap,bots

I would like to make a sitemap for my website that is made in Laravel framework. Default .htaccess file in Laravel application looks like this:

<IfModule mod_rewrite.c>

<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

</IfModule>

As far as I know, this .htacces is redirecting every request to index.php. Now what if sitemap.xml file is in root directory and in robots.txt is path to the sitemap? Search engine bot should make request like 'www.example.com/sitemap.xml' to find and read sitemap file, right? But how can bots find this file, when .htaccess is redirecting every request to index.php?

Best How To :

Don't worry. Request is redirected to index.php if:

  • It's not an existing directory:

    RewriteCond %{REQUEST_FILENAME} !-d

  • It's not an existing file:

    RewriteCond %{REQUEST_FILENAME} !-f

Laravel - Angular Routes

php,angularjs,laravel

I had similar problem. I modified the render function in app\Exceptions\Handler.php to public function render($request, Exception $e) { if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) { return response()->view('index'); } return parent::render($request, $e); } and created an index.blade.php view in resources\views folder, which was like <?php include public_path().'/views/index.html'; and it contains all the angular...

Rewrite url not working in htaccess

php,apache,.htaccess,mod-rewrite,url-rewriting

QUERY_STRING is only used to match query string without URI. You need to use: Options -MultiViews RewriteEngine On RewriteBase /mywbsite/ RewriteCond %{THE_REQUEST} /search_data\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_data.php?keywords=$1&f=$2 [QSA,L,NC] ...

PDF as mail attachment - Laravel

laravel,pdf,sendmail

You can only send serializable entities to the queue. This includes Eloquent models etc. But not the PDF view instance. So you will probably need to do the following: Mail::queue('emails.factuur', array('factuur' => $factuur), function($message) { $pdf = PDF::loadView('layouts.factuur', array('factuur' => $factuur)); $message->to(Input::get('email'), Input::get('naam'))->subject('Onderwerp'); $message->attach($pdf->output()); }); ...

custom orderBy() on constraining eager loads?

laravel,eager-loading

Something like this may work... the idea is to add an additional select which is 0 or 1 depending on if the date is today. Then you can order by that column first, then the actual date second. public function scopeRestaurantsWithMenusToday($query, $city_uri){ return $query->where('city_uri', '=', $city_uri)->with([ 'restaurants', 'restaurants.menusToday' => function($query)...

Unable to connect to your database server using the provided settings in Codeigniter

mysql,.htaccess,codeigniter

$db['default']['password'] = ''; there is an space, remove it use below settings $db['default']['hostname'] = 'localhost'; $db['default']['username'] = 'root'; $db['default']['password'] = ''; $db['default']['database'] = 'test_bs'; $db['default']['dbdriver'] = 'mysql'; $db['default']['dbprefix'] = ''; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ''; $db['default']['char_set'] = 'utf8'; $db['default']['dbcollat'] = 'utf8_general_ci';...

problems understanding workflow and set up of vagrant and laravel homestead

laravel,vagrant,virtual-machine,homestead

Are you using cygwin? You should run the commands inside the Homestead folder which is created after you do homestead init. Then you do the configuration or mapping of folders in your Homestead.yaml. it is located in you home directory. in my case in created a .homestead folder. I'm using...

Set options for ZADD command in laravel redis

php,laravel,redis,set

Until Predis' zAdd method is updated to support the changes in Redis v3.0.2, your best bet is to explore the wonderful world of RawCommand: https://github.com/nrk/predis/blob/master/src/Command/RawCommand.php It should let you construct your own commands, including the ZADD NX ... variant....

Given an array/object of datetimes, how can I return an array/object of the times sorted by hour and times sorted by days of the week

php,arrays,sorting,datetime,laravel

You can use Laravel's collection groupBy method to group your records for your needs. $records = YourModel::all(); $byHour = $records->groupBy(function($record) { return $record->your_date_field->hour; }); $byDay = $records->groupBy(function($record) { return $record->your_date_field->dayOfWeek; }); Remember that this code to work, you have to define your date field in the $dates Model array, in...

Apache Regex How To Get This Value

php,regex,apache,.htaccess

The query string is separate from the request uri. In your case you only want to add a value to it, so you can use the [QSA] (Query String Append) flag to pass the entire query string with the value you captured from the URI Try: RewriteRule ^demo/(.*)$ demo.php?utm_campaign=$1 [L,NC,QSA]...

How can I Echoing Data After Checking For Existence in PHP Laravel 5?

php,laravel,laravel-5

{{ $var or 'No Phone' }} === {{ isset($var)? $var : 'No Phone' }} Because $user->phone is defined you should use this: {{ $user->phone? $user->phone : 'No Phone' }} Or, you can go nice Laravel way and create your own directive for Blade templates and use it like this: @var($user->phone,...

Laravel 5 pagination with trailing slash redirect to 301

php,laravel,redirect,pagination,laravel-5

If you look in your app/public/.htaccess file you will see this line: # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] By removing it you will disable trailing slash redirect....

laravel file uploading using json

jquery,ajax,json,laravel,laravel-5

Use this as your code: e.preventDefault(); var mydata = new FormData($('#my_form')[0]); $.ajax({ type: 'POST', cache: false, dataType: 'JSON', url: 'tasks', data: mydata, processData: false, contentType: flase success: function(data) { console.log(data); }, }); Note that this doesn't work on some older browsers such as IE 9 or older so you might...

after using mod_rewrite link are not found

php,.htaccess,mod-rewrite

So you want the assets to be requested correctly? I guess you're using incorrect relative paths for linking those in your page's code (something like "images/image.jpg"..). If that's the folder structure you have, try to go one level up and use this path: <img src="../admin/images/image.jpg" ... or, in the case...

Htaccess rewrite URL with virtual directory and 2 variables

regex,apache,.htaccess,url,rewriting

ok , I assume you want to change the URI from http://www.example.com/result.php?team=arsenal&player=ospina to http://www.example/subdirectory/arsenal/ospina.html so this is the .htaccess that will do that for you RewriteEngine on RewriteCond %{QUERY_STRING} ^team=(.*)\&player=(.*)$ RewriteRule ^(.*)$ http://www.example.com/subdirectory/%1/%2.html [R=301] you can test it with htaccess tester here http://htaccess.madewithlove.be/ and some useful links for documentation and...

Using framework event dispatcher to raise domain event

php,events,laravel,domain-driven-design,dispatcher

Lately I favor returning events from domain methods and handling those in the application service layer. Since the application service layer is where you bring together all kinds of infrastructure further processing of the returned events, such as dispatching, can be handled in the application service layer. In this way...

How to write .htaccess file for AJAX page

php,jquery,ajax,.htaccess

I think it's more related to apache than ajax. Anyway - your RewriteRule is ^findcontents/([A-Za-z0-9-]+)/?$ and you post to the url '/findcontents'. Did you try to post to '/findcontents/asdf' ? Another option is to add ^findcontents$ to your rules. If none of these works for you please provide some more...

Payum Laravel Package - Route not found

laravel,nvp

My suspicion is that the third parameter is expecting a route name, not a URL. Your routes.php route is not a named route. Route::get('done', ['as' => 'done', 'uses' => '[email protected]']); ...

Laravel relation many to many with additional pivot

php,laravel,laravel-4

As per your requirement, I blieve you have to update your relation to Polymorphic Relations. and than to access other attributes try one of them method. $user->roles()->attach(1, ['expires' => $expires]); $user->roles()->sync([1 => ['expires' => true]]); User::find(1)->roles()->save($role, ['expires' => $expires]); If you still facing some dificulties to handle that requirement let...

Handling 500 Internal Server Error from DomDocument in Laravel 5

php,laravel,exception-handling,laravel-5

You could handle this in Laravel app/Exceptions/Hnadler.php NB: I have looked in the option of using DOMException handler which is available in PHP, however the error message you are getting in not really and exception by an I/O Warning. This what PHP native DomException looks like: /** * DOM operations...

How to rewrite example.com/catelogue.php?page=3&cat1=fruit&cat2=apple with .htaccess

php,apache,.htaccess,mod-rewrite,url-rewriting

This should work. Try your rules this way. It works for me. Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^catelogue/([^/]+)/([^/]+)$ catelogue.php?page=3&cat1=$1&cat2=$2 [NC,L] RewriteRule ^catelogue/?$ catelogue.php?page=3 [NC,L] RewriteRule ^home/?$ index.php?page=1 [NC,L] ...

Laravel validator vs requests

laravel,laravel-5,laravel-validation

1. Theoretically there is no difference between Controller validation and Validation using FormRequest. Normally you should use FormRequest. This will keep your controller clean and Minimal. But some time it is sensible to use Validator within controller, e.g you know there is going to be just one field to validate,...

Remove plus sign from url using .htaccess

php,regex,apache,.htaccess,mod-rewrite

You can add a new rule for +/- conversion: Options -MultiViews RewriteEngine On RewriteBase /indianrealitybytes/ RewriteCond %{THE_REQUEST} /search_advance\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^([^+]*)\+(.*)$ $1-$2 [R=302,NE,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_advance.php?keywords=$1&f=$2 [QSA,L,NC] ...

Page doesn't load after .htaccess redirect with parameters

php,.htaccess,url-rewriting

The order of your directives is incorrect. Use it as below instead: Options +FollowSymlinks Options -Indexes ErrorDocument 404 /404.php RewriteEngine On RewriteBase / # Add "www." RewriteCond %{HTTP_HOST} ^example.com$ RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] # Rewrite profile/x/x/x to profile.php RewriteRule ^profile/([^/]*)/([^/]*)/([^/]*)/?$ profile.php?url=$1&id=$2&ref=$3 [L] ...

Laravel5: Access public variable in another class

php,class,oop,laravel,laravel-5

That's simple php stuff. Set the attribute as static and access it with ::. class LanguageMiddleware { public static $languages = ['en','es','fr','de','pt','pl','zh','ja']; } @foreach (App\Http\Middleware\LanguageMiddleware::$languages as $lang) ... @endforeach You should not have that in a middleware though. You'd better add a configuration (i.e in /config/app.php) with that array, and...

Eloquent model not updating updated_at timestamp

php,laravel,timestamp,eloquent

As mentioned in comments, if the model did not change the timestamps wont be updated. However if you need to update them, or want to check if everything is working fine use $model->touch() - more here

Excluding certain pages from being redirected to https

wordpress,.htaccess,redirect,https,http-redirect

Try using THE_REQUEST instead of REQUEST_URI: <IfModule mod_rewrite.c> RewriteEngine On # Go to https if not on careers RewriteCond %{SERVER_PORT} =80 RewriteCond %{THE_REQUEST} !/careers/[\s?] [NC] RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L] # Go to http if you are on careers RewriteCond %{SERVER_PORT} !=80 RewriteCond %{THE_REQUEST} /careers/[\s?] [NC] RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R,L] </IfModule>...

How to delete only the table relationed

sql,laravel,migration

When creating a foreign key constraint, you can also decide what should happen with the constraints. For instance, if you want to delete all articles when a category is deleted (as I guess is your question): Schema::table('articulos', function($table) { $table->foreign('categoria_id')->references('id')->on('categorias')->onDelete('cascade'); $table->foreign('creador_id')->references('id')->on('users'); }); Also see documentation. The cascade identifies to the...

Join this eloquent laravel5

php,laravel

The relation is a hasMany and will therefor return a collection set, not one "echoable" thing: $mensajes = Messageuser::find(1)->conversaciones()->get(); $mensajes2 = Messageuser::find(4)->conversaciones()->get(); \dd($mensajes, $mensajes2); This will return two Collection objects dumped. Please also note that you can use: $mensajes = Messageuser::find(1)->conversaciones; To get the same return set. Now you want...

Setting up a second Homestead Laravel app

laravel,laravel-5,homestead

The problem was in your homestead.yaml file. folders: - map: C:\Users\Lisa\Documents\Homestead\larapipeline to: /home/vagrant/Code/larapipelin - map: C:\Users\Lisa\Documents\Homestead\tinkertower to: /home/vagrant/Code/tinkertower sites: - map: homestead.app to: /home/vagrant/Code/larapipeline/public - map: tinkertower.app to: /home/vagrant/code/tinkertower/public Don't forget to edit your hosts file. Now run vagrant up --provision, or vagrant reload --provision. Edit: Fixed case sensitivity issue...

Pretty URLs aren't working after upgrade to Mediawiki 1.24.2

.htaccess,ubuntu,mediawiki

Make sure, that you checked the following points: - the mod_rewrite module is enabled - you allow the htaccess to overwrite the settings you want (check, if the AllowOverwride directive is set, e.g. (that would be the easiest value) to all, see http://httpd.apache.org/docs/current/de/mod/core.html#allowoverride # your directory definition AllowOverwride All #...

Rewrite non-dynamic pages using htaccess

apache,.htaccess,mod-rewrite

Try the following rules in your /htaccess file : RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^.-]+)\.php [NC] RewriteRule ^ %1/ [NC,R,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^-]+)-([^.]+)\.php [NC] RewriteRule ^ %1/%2/ [NC,R,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ $1.php [QSA,NC,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/?$ $1-$2.php [QSA,NC,L] ...

Laravel 5 MethodNotAllowedHttpException

php,laravel,laravel-5,laravel-routing

Your <a> link will trigger a GET request, not a PATCH request. You can use JS to have it trigger a PATCH request, or use a <button> or <input type="submit"> to issue one.

Force WWW when URL contains path using .htaccess

.htaccess,session,url,redirect

It seems to look ok but one thing you should do is always put your other rules before the wordpress rules as a habit. When using wordpress it should generally be the last set of rules since it does all the routing. Now for the redirect, you should probably use...

What does “as” keyword really mean in Laravel routing?

laravel,laravel-routing

The purpose isn't for re-direction in your routing file. Instead, with the example route you provided, Laravel will allow you to reference said route by using: $url = route('profile'); Rather then having to build the url manually in your code. So, in short: the difference is the first thing is...

Best way to block countries [on hold]

php,apache,.htaccess

You don’t have to fill your .htaccess file with thousands of lines of IPs. Instead, you can install a C library and an Apache module to do the heavy lifting for you. MaxMind provides a popular free database that is often used for IP lookups. Their GeoLite2 is a free...

Pattern matching in htaccess rewrite condition

apache,.htaccess,mod-rewrite,https

You need to tell the RewriteCond what to match !/go/ against. Change the second line to: RewriteCond %{REQUEST_URI} !/go/ [NC] ...

How to change default Nginx setting on Homestead Laravel Virtualbox VM

laravel,nginx,vagrant,virtualbox,homestead

Easiest way to achieve this is editing scripts/serve.sh file, which contains server block template in block variable.

Laravel 4.2 Sending email error

php,email,laravel,laravel-4

Closures work just like a regular function. You need to inject your outer scope variables into function's scope. Mail::send('invoices.mail', array($pinvoices,$unpinvoices), function($message) use ($email) { $message->to($email , 'Name')->subject('your invoices '); }); ...

How to register global variable for my Laravel application?

php,laravel,laravel-5

Actually, you should reserve in config/app.php file. Then, you can add In the Service Providers array : 'Menu\MenuServiceProvider', In the aliases array : 'Menu' => 'Menu\Menu', Finally, you need to run the following command; php artisan dump-autoload I assume that you already added this package in composer.json Sorry, I didn't...

Redirect specific Url variables

php,.htaccess,mod-rewrite,redirect

Try this : RewriteEngine On RewriteCond %{QUERY_STRING} ^s=([^&]+)&type=([^&]+) [NC] RewriteRule ^data.php$ /d.php?s=%1&t=%2 [NC,R,L] This will externally redirect a request for : /data.php?s=foo&type=bar to /d.php?s=foo&t=bar ...

Laravel 5: How to add Auth::user()->id through the constructor ?

authentication,laravel,constructor

You can use Auth::user() in the whole application. It doesn't matter where you are. But, in response to your question, you can use the 'Controller' class present in your controllers folder. Add a constructor there and make the reference to the user ID. <?php namespace App\Http\Controllers; use Illuminate\Foundation\Bus\DispatchesCommands; use Illuminate\Routing\Controller...

Redirection loop (URL rewriting)

regex,apache,.htaccess,mod-rewrite,rewriting

I suggest not using .php in pretty URL, make it extension-less. Try these rules in v2/.htaccess: RewriteEngine On RewriteBase /v2/ RewriteCond %{THE_REQUEST} /message\.php\?ID2=([^&\s]+) [NC] RewriteRule ^ message-%1? [NE,R=302,L] RewriteRule ^message-(.+)/?$ message.php?ID2=$1 [L,QSA,NC] ...

Laravel belongsTo throwing undefined function App/BelongsTo() exception

php,sql,laravel,eloquent,belongs-to

Well, this error occurred because I had '.' in place of '->'. I couldn't figure out why it was always throwing the exact same error regardless if I did $this.belongsTo('App\User'); or $this.hasMany('App\User'); or even $this.thecakeisalie('App\User'); until I sat staring at the text between my many models yet again. Then, lo...

Laravel Interfaces

php,laravel,interface,namespaces

In my recent laravel 5 project, I'm used to prepare my logics as Repository method. So here's my current directory structure. For example we have 'Car'. So first I just create directory call it libs under app directory and loaded it to composer.json "autoload": { "classmap": [ "database", "app/libs" //this...

Admin login laravel 4

php,laravel

In your admin template you set the goto url as sessions.store which hits SessionsController::store in that method you have a debug function dd() which is throwing that string. It get's called because auth::attempt() returns false as by your own code: if($attempt) return Redirect::intended('/'); So the behavior is exactly doing what...

htaccess errors after upgrading Apache from 2.2 to 2.4

apache,.htaccess

The NoCase ([NC]) doesn't even make sense there as you're not matching anything. Just take it out. RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1\.php -f RewriteRule ^(.+?)/?$ /$1.php [L] ...

mod_rewrite - force redirecting to rewritten URL

apache,.htaccess,mod-rewrite,redirect

You need a new rule for that redirect: Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} /(?:index\.php)?\?search=([^\s&]+) [NC] RewriteRule ^ search/%1? [R=302,L,NE] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^search/(.*)$ /?search=$1 [L,QSA] ...

Codeigniter URL routing issues in .htaccess

php,apache,.htaccess,codeigniter-2

Okay, as stated before I am not a CodeIgniter guru. What I do know is that the following works for me: Config: $config['base_url'] = "http://www.deltadigital.ca/"; # or use $config['base_url'] = ""; $config['uri_protocol'] = "REQUEST_URI"; $config['index_page'] = ''; Routes: $route['default_controller'] = "tlc/view"; $route['(:any)'] = "tlc/view/$1"; $route['404_override'] = ""; Controller: <?php if...

Getting code from my forked repository

git,laravel,repository,laravel-5,composer-php

Having a look at your repository in https://github.com/Yunishawash/api-guard it looks like it doesn't have a branch called dev-fullauth. Instead there is a branch dev-bugfix. But you must not name your branch including the dev- prefix. Rename your branch at github from dev-bugfix to bugfix and then your require section would...

What is the best practice to implement update profile picture in PHP Laravel 5?

javascript,php,jquery,laravel,laravel-5

I solved it by doing this HTML {!! Form::model($user, array('route' => array('user.update_profile_picture', $user->id ),'method' => 'PUT')) !!} <a class="pmop-edit" > <span id="file-upload" > <i class="md md-camera-alt"></i> <span class="hidden-xs">Update Profile Picture</span> </span> <div style='height: 0px;width: 0px; overflow:hidden;'> <input id="upfile" type="file" value="upload" onchange="sub(this)" /> </div> </a> {!! Form::hidden('$id', $user->id)!!} {!!...